Is it possible for me to draw ABOVE all controls on a form
?
I have some controls (textboxes
, buttons
, COM objects
) on my form,
and I wish to draw ON them, overriding any pixels previously drawn by them.
I am using Windows Forms
on C#
.
NOTE: the Graphics
class draws under the controls...
I know I'm way too late in the game, and there is nothing wrong with the accepted answer, but I found it too complicated and somehow hard to understand, so I come up with a "hack" for it.
1. Make a custom Panel
with the following code.
public class TransparentPanel : Panel
{
protected override void OnPaint(PaintEventArgs e)
{
}
protected override void OnPaintBackground(PaintEventArgs e)
{
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
}
2. Create a TransparentPanel
exactly the same size as the Form
, over every control currently on the Form
, bring it to the front, and set its BackColor
to Transparent
, Enable
to false
.
3. Now everything you draw within OnPaint
will be drawn "above" any controls, and it will not "block" any interactable controls such as TextBox
.
精彩评论