Hi!
I'm using IG 11.2 CLR4x, and in the application I have a Office 2007 like ribbon, on wich I'm trying to put a label. The problem is that the background of the label is not transparent (even though in its properties it is set to transparent).
What can I do ? Thank you!
Hi mismar,
If you have any further questions regarding this approach, please let me know.
Sincerely,Chris KDeveloper Support EngineerInfragistics, Inc.www.infragistics.com/support
It looks like although my initial approach will allow you to draw the text anywhere on the form, the Ribbon area is actually rendered after the form is painted. So even though the text is present, it is obstructed from view by the ribbon.
Now worries though, I have worked around this behavior with the use of a simple draw filter implementation, wherein the text is explicitly drawn after the UltraToolbarsManager and its ribbon have rendered.
I have constructed and attached a sample, using this approach, which I have tailored to the conditions in your screenshot, where I am using the textEditor’s location to position the remaining text that would otherwise be rendered by your labels.
Please find the sample attached.
I have also provided the necessary code below, for reference.
public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Load += new EventHandler(Form1_Load); } void Form1_Load(object sender, EventArgs e) { ultraToolbarsManager1.DrawFilter = new RibbonDrawFilter(); (ultraToolbarsManager1.DrawFilter as RibbonDrawFilter).textEditorLoc = ultraTextEditor1.Location; } private class RibbonDrawFilter : IUIElementDrawFilter { public Point textEditorLoc { get; set; } bool IUIElementDrawFilter.DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams) { return false; } DrawPhase IUIElementDrawFilter.GetPhasesToFilter(ref UIElementDrawParams drawParams) { Font font = new Font("Arial", 9); drawParams.Graphics.DrawString("History comment", font, new SolidBrush(Color.Black), textEditorLoc.X, textEditorLoc.Y + 25); drawParams.Graphics.DrawString("This comment valid for the whole transaction", font, new SolidBrush(Color.Black), textEditorLoc.X, textEditorLoc.Y + 40); return DrawPhase.AfterDrawElement; } } }
If you have any further questions at all regarding this approach, please let me know.
Thank you Chris or both the explanations and the suggestion.
I've gave it a shot, using your approach but Nothing gets painted on the ribbon. Wha am I doing wrong ?
private void MainForm_Paint(object sender, PaintEventArgs e)
{
System.Drawing.Graphics formGraphics = this.CreateGraphics();
string drawString = "Sample Text";
System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);
System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
float x = 400;
float y = 84;
System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat();
formGraphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
drawFont.Dispose();
drawBrush.Dispose();
formGraphics.Dispose();
}
The behavior that you are observing is in fact expected behavior. The reason that the UltraLabel does not appear to apply the transparent appearance as you are expecting is that .NET controls, which many controls such as the UltraLabel are derived from do not actually support true transparency.
In instances where you are setting the control’s background to transparent, they will actually take on the background color of their parent control.
In this case, the label that you are using is in fact taking on the background color of its parent control, which is the form or Fill_Panel if one was implemented; the color used in this case appears to be the default background color, “Control”.
In the following screen shot, this same behavior is demonstrated with the .NET Label, where the form's BackColor is set to blue; note how the transparent label takes on the new appearance of its parent.
If you are only trying to display text within the ribbon, I would recommend using the DrawString() method extended from the graphics object of the form, within the forms paint event handler.
Using this approach you will be able to place your text anywhere on the form while maintaining the transparency behavior that you are looking for.
If you have any questions at all regarding this approach, please let me know.