Miftakhov
Miftakhov

Reputation: 48

Please tell me how can I make label1 background transparent?

Please tell me how can I make label1 background transparent?

This does not work.

label1.BackColor = Color.Transparent;

Upvotes: 0

Views: 265

Answers (1)

Rion Williams
Rion Williams

Reputation: 76597

The use of the BackColor property should be correct, however you'll also need to ensure that the specific control you are using has support enabled for a transparent background as mentioned in the documentation :

The BackColor property does not support transparent colors unless the SupportsTransparentBackColor value of System.Windows.Forms.ControlStyles is set to true.

By default a Label will pull the background color of it's container, so if it was simply on a Form directly, you should be able to use :

public Form1()
{
        InitializeComponent();
        // Indicate this form would explicitly support transparency
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        BackColor = Color.Transparent;
        // Make your label transparent
        label1.BackColor = Color.Transparent;
}

Otherwise, you'll need to make sure that it's container element supports transparency and is transparent.

Upvotes: 2

Related Questions