How can I make my controls transparent so the form’s background image can show through them

Platform: WinForms| Category: Controls

By default, a control’s background color will be the same as the container’s background. In the picture below, the form’s background was set to Color.Red. In design mode, you can see the four controls have the red background, but since the form’s Image was set to a bitmap, you cannot see the form’s red background. To make the controls’ background transparent, you can set the alpha blend value of their background to zero. In code, you could use:

  public Form1()
  {
    InitializeComponent();

    checkBox1.BackColor = Color.FromArgb(0, checkBox1.BackColor);
    button1.BackColor = Color.FromArgb(0, button1.BackColor);
    linkLabel1.BackColor = Color.FromArgb(0, linkLabel1.BackColor);
    label1.BackColor = Color.FromArgb(0, label1.BackColor);
    // Or use the System.Drawing.Color.Transparent color.
  }

In design mode, you can set the alpha blend value to zero by typing the four component in the property grid. So, for each control’s BackColor property, you would type 0,255,0,0 to make it a transparent red.

Here is a VB project using this idea.

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.