Reputation: 1783
How do you draw a string that is supposed to be on top of everything else? Right now in my panel i have some user controls in Panel1.Controls. So i added this to the Paint method:
Graphics g = Panel1.CreateGraphics();
g.DrawString("BUSTED", new Font("Arial", 20f), new SolidBrush(Color.Black), new PointF(50, 50));
The problem is that the text is printed behind the user controls, so it can't be seen. (If i change the position of the text out in the open, it's displayed correctly).
Any ideas?
Upvotes: 2
Views: 22581
Reputation: 49978
Im not sure it will work, but you could try SendToBack on all user controls inside the panel, then maybe the text will show on top.
Upvotes: 1
Reputation: 2411
All windows forms controls are HWND based, meaning they each have their own window handle and the z-order/parent-child of the controls determines what clips what. The panel paint event is painting onto the panel control, but the panel controls output is clipped by all it's child controls.
Transparency does not work correctly in windows forms. If you set something to have a transparent background, it will typically wind up having the form background show through, and not it's immediate parents.
I have worked around this in various ways.
Upvotes: 2
Reputation: 16168
what about overriding OnPaint in Panel, and writing your drawing code AFTER the base paint?
class DrawingPanel : Panel {
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
// Your drawing code here
}
}
Upvotes: 0
Reputation: 2408
Try adding panel that is over all your controls then drawing in it. The panel must be set with transparency.
Here's more info : Drawing on top of controls inside a panel (C# WinForms)
Upvotes: 1