Hey All.

I'm needing a fully transparent label to rest over a picture field that gets resized from calculations. The picture field is simple a background image in a PictureBox that represents a percentage of a whole. The label stores the actual percentage text.

Here's the issues I've come across:

  • Making the Picture Box a panel and instead placing the Label in it will hide the label if the percentage is too small
  • Adding a Label on top of the Picture box and setting it to transparent get thes Forms background color, not the picture that it is over
  • I couldn't get the _Paint to set the text to work at all for some reason (I'll post code below)
  • Setting the Labels parent to the PictureBox seems to take way too much code for what it does
private void pictureBar_Paint(object sender, PaintEventArgs e)
{
    using (Font myFont = new Font("Arial", 14))
    {
        e.Graphics.DrawString("test", myFont, Brushes.Green, new Point(2, 2));
    }
}

I've been searching for a few hours now and I can't find any really applicable way to tackle this. Anyone have any ideas/suggestions?

I also found this: http://www.doogal.co.uk/transparent.php
It may work but I can't seem to get it to show up on my form. Is there a way to add it to the toolbox so I can drag-and-drop it? Creating a new TransparentLabel, setting the location, text and visibility doesn't get it to show up.

Edited 6 Years Ago by SacredFootball: n/a

I'm also running into many sites telling me to create a new "Windows Form Control Library". I don't have this option when creating a new project. Is this only available for the professional edition? I'm using express.

Hey All.

I'm needing a fully transparent label to rest over a picture field that gets resized from calculations. The picture field is simple a background image in a PictureBox that represents a percentage of a whole. The label stores the actual percentage text.

Here's the issues I've come across:

  • Making the Picture Box a panel and instead placing the Label in it will hide the label if the percentage is too small
  • Adding a Label on top of the Picture box and setting it to transparent get thes Forms background color, not the picture that it is over
  • I couldn't get the _Paint to set the text to work at all for some reason (I'll post code below)
  • Setting the Labels parent to the PictureBox seems to take way too much code for what it does
private void pictureBar_Paint(object sender, PaintEventArgs e)
{
    using (Font myFont = new Font("Arial", 14))
    {
        e.Graphics.DrawString("test", myFont, Brushes.Green, new Point(2, 2));
    }
}

I've been searching for a few hours now and I can't find any really applicable way to tackle this. Anyone have any ideas/suggestions?

I also found this: http://www.doogal.co.uk/transparent.php
It may work but I can't seem to get it to show up on my form. Is there a way to add it to the toolbox so I can drag-and-drop it? Creating a new TransparentLabel, setting the location, text and visibility doesn't get it to show up.

I got it to work by using the site mentioned above. I couldn't figure out how add the control to my toolbox. Figured out I had to build the solution so it'd build the dll file. Works great. I just have to figure out how to align the text in the label now

Hi,

you can use the normal label class. Just set the background color like this:
label.BackColor = Color.FromArgb(alpha, color);
alpha is a value of 0 to 255, where 0 is fully transparent, 255 fully opaque.

Now i found a working solution without a new class :)
You have to add the label directly to picturebox.Controls.
for example:
Label label = new Label {Text = "test", AutoSize = true, BackColor = Color.Transparent};
pictureBox.Controls.Add(label);

This article has been dead for over six months. Start a new discussion instead.