How can I set a label transparent?

R

Rudy

Hi there,

got a little problem with backcolor aof labels:
I have a picture box and a label on top of it. But when setting the
backcolor of the label transparent, I still see the grey rectangle of the
label and not the picturebox behind the text. How can I realize this?

Thanx

Rudy
 
M

Morten Wennevik

Hi Rudy,

A way around this, not using labels, is to drawstring the text directly onto the picturebox. You can still put a label ontop of the picturebox and use it in design and at runtime, but set it to visible = false and let the drawstring paint it, using whatever property label1 has.

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawString(label1.Text, label1.Font, new SolidBrush(label1.ForeColor), label1.Left - pictureBox1.Left, label1.Top - pictureBox1.Top);
}


Happy coding!
Morten Wennevik [C# MVP]
 
R

Rudy

Thank you very much!

Morten Wennevik said:
Hi Rudy,

A way around this, not using labels, is to drawstring the text directly
onto the picturebox. You can still put a label ontop of the picturebox and
use it in design and at runtime, but set it to visible = false and let the
drawstring paint it, using whatever property label1 has.
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawString(label1.Text, label1.Font, new
SolidBrush(label1.ForeColor), label1.Left - pictureBox1.Left, label1.Top -
pictureBox1.Top);
}


Happy coding!
Morten Wennevik [C# MVP]
 

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