creating a truly transparent control
-
Hi, Easy question here. I found this online, but (I'm still new to programming) I'm not sure how to use it.
protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT return cp; } }
Do I create a new class for this code? Either way, how and where do I say that I want a label (not all labels) to be this way. Thanks so much!!! Mel :) -
Hi, Easy question here. I found this online, but (I'm still new to programming) I'm not sure how to use it.
protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT return cp; } }
Do I create a new class for this code? Either way, how and where do I say that I want a label (not all labels) to be this way. Thanks so much!!! Mel :)Hi again, Ok, I created a class and put the code in it.
public class TransparentControl : Label { protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT return cp; } } }
Back in the normal form, I made the labelprivate TransparentControl label7;
and changed the appropriate line in InitializeComponent()this.label7 = new HCAUT.TransparentControl();
. I also made the backcolor of the label Transparent. But when I run everything, the label's backcolor still isn't transparent. Can anyone see what I'm doing wrong? Thanks again, Mel -
Hi again, Ok, I created a class and put the code in it.
public class TransparentControl : Label { protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT return cp; } } }
Back in the normal form, I made the labelprivate TransparentControl label7;
and changed the appropriate line in InitializeComponent()this.label7 = new HCAUT.TransparentControl();
. I also made the backcolor of the label Transparent. But when I run everything, the label's backcolor still isn't transparent. Can anyone see what I'm doing wrong? Thanks again, Melhi melanieab! :) i think if you inherited the Label, it already supports transparency. try to remove the override property you've added. if still doesn't allow transparency, add this line of code on the constructor of your control.
SetStyle(ControlStyles.SupportsTransparentBackColor, true)
hope that helps! :) microsoc :cool: