Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reasons for why a WinForms label does not want to be transparent?

Why can't I set the BackColor of a Label to Transparent? I have done it before, but now it just don't want to...

I created a new UserControl, added a progressbar and a label to it. When I set the BackColor of the label to transparent it is still gray =/ Why is this?

What I wanted was to have the label on top of the progressbar so that its text was "in" the progressbar...

like image 555
Svish Avatar asked Mar 03 '09 10:03

Svish


People also ask

How do I make labels transparent in Visual Studio?

To make a label transparent you need to set the forms transparencykey to lets say maroon "or a color you never will use". Then if you set the label Backcolor to Maroon it will be transparent.

How do you make a button transparent in Windows Forms?

Its simple try this. Click the button that you want to make transparent. Select FlatStyle from Properties and set it to popup Now change the BackColor property to Transparent . This will make the button transparent.

How do I hide a label in Windows form?

You are allowed to set the visibility of the Label control using the Visible Property in the windows form. The label is visible when the value of this property is set to be true. Step 2: Drag the Label control from the ToolBox and drop it on the windows form.


1 Answers

Add a new class to your project and post the code shown below. Build. Drop the new control from the top of the toolbox onto your form.

using System; using System.Windows.Forms;  public class TransparentLabel : Label {   public TransparentLabel() {     this.SetStyle(ControlStyles.Opaque, true);     this.SetStyle(ControlStyles.OptimizedDoubleBuffer, false);   }   protected override CreateParams CreateParams {     get {       CreateParams parms = base.CreateParams;       parms.ExStyle |= 0x20;  // Turn on WS_EX_TRANSPARENT       return parms;     }   } } 
like image 90
Hans Passant Avatar answered Sep 27 '22 19:09

Hans Passant