Why can't I set the BackColor of a Label to Transparent? I have done it before, but now it just don't want to...
I created a new UserControl, added a progressbar and a label to it. When I set the BackColor of the label to transparent it is still gray =/ Why is this?
What I wanted was to have the label on top of the progressbar so that its text was "in" the progressbar...
To make a label transparent you need to set the forms transparencykey to lets say maroon "or a color you never will use". Then if you set the label Backcolor to Maroon it will be transparent.
Its simple try this. Click the button that you want to make transparent. Select FlatStyle from Properties and set it to popup Now change the BackColor property to Transparent . This will make the button transparent.
You are allowed to set the visibility of the Label control using the Visible Property in the windows form. The label is visible when the value of this property is set to be true. Step 2: Drag the Label control from the ToolBox and drop it on the windows form.
Add a new class to your project and post the code shown below. Build. Drop the new control from the top of the toolbox onto your form.
using System; using System.Windows.Forms; public class TransparentLabel : Label { public TransparentLabel() { this.SetStyle(ControlStyles.Opaque, true); this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false); } protected override CreateParams CreateParams { get { CreateParams parms = base.CreateParams; parms.ExStyle |= 0x20; // Turn on WS_EX_TRANSPARENT return parms; } } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With