Label Transparent on picturebox vs 2005 c#

  • Thread starter Thread starter alexei.x
  • Start date Start date
A

alexei.x

Searching the net to get a way to draw transparent labels like in VB6
with background picture boxes i found some messages
and here is a little routine wich will save some time
this routine will draw all labels with transparent background...
enjoy :

1) Create a PictureBox with an image, name it picBack
2) create a lot of labels
3) in properties of PictureBox clicke events and doubleckick Paint
event
4) insert following code:

//picBack is PictureBox control
private void picBack_Paint(object sender, PaintEventArgs e)
{
foreach (Control C in this.Controls)
{
if (C is Label)
{
Label L = (Label)C;
L.Visible = false;
e.Graphics.DrawString(L.Text, L.Font, new
SolidBrush(L.ForeColor), L.Left - picBack.Left, L.Top - picBack.Top);
}
}
}
 
Hi,

Wouldn't it be simpler to create a simple owner-draw control whose Paint
handler would just do the same:

e.Graphics.DrawString(...)

using the transparent brush as the background? ;-)
 
Back
Top