Geekpedia Forums Logo

c# disapointment at non transparent controls

by Lewis Cowles on Saturday, October 6th - 6:01 PM



I am soooo Upset right now because I have only just realised that c# does not allow for true object transparency, If anyone knows how to make a label truely transparent(meaning it has no background even over other objects such as labels) please let me know or post a tutorial on how to acheive this, thanx

Hmm... did you try the SetStyle method?

SetStyle(ControlStyles.Opaque, false);

Yes It seems that all methods of making the control transparent are making the control inherit the background color from the parent control, it is very confusing and a bad show as I was making a tutorial for geekpedia at the time on a windows forms based carousel (Its also a project for my little neice) maybe It's because of the controls that I am using (picturebox and label) any further ideas

 

Transparent panels in .NET are not really transparent. Setting the background color to transparent causes the background of the panel to match that of the control it inhabits. This creates an issue when you have 2 panels in the same control because they wont appear as transparent if overlapped. This is indeed very weak.

To actually set the background of the control to true transparency, try overriding the CreateParams property and the OnPaintBackground method as follows:


protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
}

protected override void OnPaintBackground(PaintEventArgs e)
{}

I had to do this to paint an overlay on a set of controls. In order to get a mouse to be able to access controls that are "through" this transparent portion, you will have to disable the transparent control.

Hope it helps!
James

Please type your message here.