How can I set a label transparent?

  • Thread starter Thread starter Rudy
  • Start date Start date
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
 
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]
 
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]
 
Back
Top