Transparent Label

E

Eric Renken

I have a form that has a picture box with an image. I will also me placing
labels on this form in front of the picture box. I want the picture to show
through the labels. I would like the labels to be transparent. I have
tried setting the background color of the label to transparent, but all it
shows is the background color and you can not see the image behind it.

Is there any way to do this?

Thanks,
 
K

Ken Tucker [MVP]

Hi,

When a controls background is set to transparent the control takes
the backgound of its parent. If the labels parent is the form the
picturebox will not show through. You need to make sure the labels parent is
the picturebox.

Ken
-------------------
I have a form that has a picture box with an image. I will also me placing
labels on this form in front of the picture box. I want the picture to show
through the labels. I would like the labels to be transparent. I have
tried setting the background color of the label to transparent, but all it
shows is the background color and you can not see the image behind it.

Is there any way to do this?

Thanks,
 
F

Frank Hileman

One way is to draw the labels yourself over the image in the picture box, or
create a custom control with a background image, and override the OnPaint
event to draw the labels.

Regards,
Frank Hileman

check out VG.net: www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor
 
J

Jeffrey Tan[MSFT]

Hi Eric,

Just as Ken stated, if you set the label's parent to picturebox, it will be
transparent on the picturebox.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
E

Eric Renken

Ken & Jeffery,

Thanks it worked great doing that. I guess my question would be why doesn't
the control get the picture box as the parent when you drop the label onto
the picture box. I assume this is because it isn't a container control. Do
you think it would work if I created inherited from the picture box into a
new control and set the Style to make it a container control?

Thanks for the help.
 
J

Jeffrey Tan[MSFT]

Hi Eric,

Yes, you are right, this is because picturebox is not a container control,
the VS.net code generation will not add the label into the Controls
collection of the picturebox.

To workaround this behavior, we may inherit from the picturebox class, then
attach a customized ParentControlDesigner to the customized control.

In the customized ParentControlDesigner, override CanParent method, and
determine if the control is label, then return true for label control.

Like this:
[Designer(typeof(TestControlDesigner))]
public class MyPictureBox : System.Windows.Forms.PictureBox
{
}

public class TestControlDesigner: ScrollableControlDesigner
{
public override bool CanParent(Control control)
{
if(control is Label)
{
return true;
}
return base.CanParent (control);
}
}
But I do not suggest to do this, because you will find that the design-time
behavior of the MyPictureBox will be something like the panel control,
which may confuse some other people.
===================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top