Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Label BackColor Transparency

Status
Not open for further replies.

apc2003

Programmer
Aug 29, 2003
54
GB
My problem is something simple so simple i can't make it work at all.

If anyone is familular with Borland software, when using a label you could set the label's background color to "Transparent = true". I've recently needed to do this in C# and found setting the "BackColor" of a label to Transparent will not work.

I need to place a label on top of a image but make it so the label backgound is completely transparent.

How do I do this? If anyone can help it would be great as this is one of them simple stupid little things that isn't as obvious as I would of hoped.

Regards in advance... :)
 
You can build the transparent you want.
For example:
this.label1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(224)), ((System.Byte)(224)), ((System.Byte)(224)));

-obislavu-
 
The example you posted is fine if your only working with a coloured background. What do I use if I want a TRUE transparency if the label is sitting on top of an image?

Regards...
 
Instead of using an actual label, why not use GDI+? Use the DrawString method in the Paint override to draw your own "labels". When you draw the text, the background of the text will be transparent.

Code:
private void Your_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
    string str = "label text";
    StringFormat format = new StringFormat();
    format.Alignment =StringAlignment.Near;
    format.Trimming = StringTrimming.None;

    RectangleF rectF = new RectangleF(0f,0f,0f,0f);
    //Define your text rectangle here//
    //You can "measure" the required rect size using:
    //SizeF sz = e.Graphics.MeasureString(str, this.Font);
    //Then just modify the rectangle's position

    //Write the text:
    e.Graphics.DrawString(str, this.Font, new SolidBrush(Color.Black), rectF, format);

}

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top