blez's : blog

code / design / music and more

How to create transparent labels in WinForms

1 Comment

If you come from VB6, you’ll notice that WinForms doesn’t have transparent labels. WHICH SUCKS if you really need them. There are workarounds like using WPF instead or drawing the ‘labels’ with DrawText. But I recently found a better way – using the LinkLabel control. It supports transparency just fine. The only thing you have to do is to disable all its link properties.
The code below shows how:

// if your LinkLabel is called linkLabel

linkLabel.ForeColor = this.ForeColor;
linkLabel.LinkColor = this.ForeColor;
linkLabel.VisitedLinkColor = this.ForeColor;
linkLabel.ActiveLinkColor = this.ForeColor;
linkLabel.DisabledLinkColor = this.ForeColor;
linkLabel.LinkArea = new LinkArea(0, 0);
linkLabel.LinkBehavior = LinkBehavior.NeverUnderline;
linkLabel.Cursor = Cursors.Arrow;
linkLabel.BackColor = Color.Transparent;
Advertisements

One thought on “How to create transparent labels in WinForms

  1. This is a incredible clever solution for which I was only missing the Cursors.Arrow part. Thanks a lot!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s