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...
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;
}
}
}