Make a user control transparent
Refer to
http://www.thescripts.com/forum/thread248836.html
http://www.peterritchie.com/Hamlet/Articles/62.aspx
Step 1:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020;
return cp;
}
}
Step 2:
Add the following lines in the constructor.
SetStyle(ControlStyles.Opaque, true);
UpdateStyles();
Step 3:
protected override void OnPaint(PaintEventArgs e)
{
// TODO: Add TransparentControl.OnPaint implementation
base.OnPaint (e);
}
Example
namespace Magnifier.NET
{
public class TransparentControl : System.Windows.Forms.UserControl
{
private System.ComponentModel.Container components = null;
public TransparentControl()
{
SetStyle(ControlStyles.Opaque, true);
UpdateStyles();
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitializeComponent call
}
protected override CreateParams CreateParams
{
get
{
const int WS_EX_TRANSPARENT = 0x20;
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_TRANSPARENT;
return cp;
}
}
protected override void OnPaint(PaintEventArgs e)
{
// TODO: Add TransparentControl.OnPaint implementation
base.OnPaint (e);
}
}
}
Labels: .NET, C#, Programming