Five steps for creating a transparent user control
Guest post from Eyal Ron:
After much testing this is the correct formula for a truly transparent user control:
- Derive from Panel rather then UserControl.
- Override the OnPaintBackground function:
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//do nothing
} - Override the OnMove function:
protected override void OnMove(EventArgs e)
{
RecreateHandle();
} - Override the CreateParams property:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle = 0×00000020; //WS_EX_TRANSPARENT
return cp;
}
} - Override the OnPaint function:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;//Do your drawing here
.
.
.g.Dispose();
}
Category: Winforms
January 31st, 2008 at 1:24 am
Awesome! This actually worked, unlike the dozen other solutions I found. Thanks!
February 3rd, 2008 at 6:49 am
You are most welcome.
February 3rd, 2008 at 6:50 am
You are most welcome.
March 13th, 2008 at 1:35 pm
I want to thank you as well. Thanks!!!