Label Transparent on picturebox vs 2005 c#

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);
}
}
}
 
D

Dmytro Lapshyn [MVP]

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? ;-)
 

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