Export (0) Print
Expand All
1 out of 17 rated this helpful - Rate this topic

How to: Give Your Control a Transparent Background

By default, controls do not support transparent backcolors. However, you can allow your control to have a background color that is opaque, transparent, or partially transparent by using the SetStyle method in the constructor. The SetStyle method of the Control class allows you to set particular style preferences for your controls, and can be used to enable or disable support for transparent backcolors.

Note Note

Windows Forms controls do not support true transparency. The background of a transparent Windows Forms control is painted by its parent.

To give your control a transparent backcolor

  1. Locate the constructor for your control class.

    The constructor appears in the control's code file. In Visual Basic, the constructor is the method named New. In C#, the constructor is the method with the same name as the control and with no return value.

  2. In the constructor, call the SetStyle method of your form.

    This will enable your control to support a transparent backcolor.

    SetStyle(ControlStyles.SupportsTransparentBackColor, true);
    
  3. After the line of code you added in the previous step, set your control's BackColor to Transparent.

    this.BackColor = Color.Transparent;
    

    Note that you can also create colors that are partially transparent using the FromArgb method. For more information on colors, see Using Managed Graphics Classes.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.