How do I make a control transparent?
The answer to the question "How do I make a control transparent?" depends on your definition of the word "transparent".
Windows Forms Transparent
In the Windows Forms world, transparent means setting the back color of a control to the same as its parent. If this is what you're trying to accomplish, the following instructions are taken from the .NET Help topic "Giving Your Control a Transparent Background":- In the Code Editor for your control, locate the constructor. Call the SetStyle method of your form in the constructor.
In C#:
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
In VB .NET:
SetStyle(ControlStyles.SupportsTransparentBackColor, True)
This enables your control to support a transparent backcolor.
- Beneath the line of code you added in step 1, add the following line. This sets your control's BackColor to Transparent:
In C#:
this.BackColor = Color.Transparent;
In VB .NET:
Me.BackColor = Color.Transparent
Really Transparent!
If you want to make the back color of a control completely transparent so you can see what's beneath it at run time, perform these steps (we've only been able to get this to work in User Controls, but you may have better luck!):- Add the following code to the constructor of the control:
In C#:
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent;
And in VB .NET:
Me.SetStyle(ControlStyles.SupportsTransparentBackColor, True) Me.BackColor = Color.Transparent
- Override your control's CreateParams method.
In C#:
protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT return cp; } }And in VB .NET:
Protected Overrides ReadOnly Property CreateParams() As CreateParams Get Dim cp As CreateParams = MyBase.CreateParams cp.ExStyle = cp.ExStyle Or &H20 'WS_EX_TRANSPARENT Return cp End Get End Property - If you want to create a border for your User Control, you can override the OnPaint event.
For example, in C#:
protected override void OnPaint (System.Windows.Forms.PaintEventArgs e) { // Call OnPaint in the base class base.OnPaint (e) ; // add our own customization System.Drawing.Pen pen = new System.Drawing.Pen (Color.Yellow, 3) ; e.Graphics.DrawRectangle(pen, 0, 0, this.Bounds.Width - 1, this.Bounds.Height - 1) ; }And in VB .NET:
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs) ' Call OnPaint in the base class MyBase.OnPaint(e) ' add our own customization Dim pen As New System.Drawing.Pen(Color.Yellow, 3) e.Graphics.DrawRectangle(pen, 0, 0, Me.Bounds.Width - 1, Me.Bounds.Height - 1) End Sub
© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 04/26/18
Comment or report problem with topic
