• 0

[VB.NET] Label Opacity


Question

7 answers to this question

Recommended Posts

  • 0

Have you tried setting the BackColor and ForeColor to something with an alpha value <255? Long shot but it might work, although I suspect that the alpha channel will get ignored.

Alternatively, what about using The "Transparent/Translucent" label control from The Code Project. Its unlicenced and you have free access to the source so you can make any necessary adjustments.

If you don't like either of those or they don't work, you could try just creating a class that inherits System.Windows.Forms.Label and override the OnPaint method to draw the label with opacity.

  • 0

the simple answer is: no, if you are using Windows Forms. yes, if you are using Windows Presentation Foundation.

the more complicated answer with Windows Forms is that it is drawn top-down, not bottom-up. you can't set transparency of a label over another control because the control on the bottom won't necessarily be drawn first... or at all. this is not true for top level windows. if you change the opacity of a label, some controls... like the Form itself, will fake it with some trickery. more fundamentally, WinForms is a wrapper for the Win32 API and that has limitations.. like alpha transparency for non top-level windows. if you see another program draw with control-level opacity, they are using some custom drawing code to make it happen - which can get very complex.

the Windows Presentation Foundation, on the other hand, is a wrapper for the DirectX APIs, which support full transparency and are drawn bottom-up. if you want to get fancy with your uis, use WPF.

  • 0

For WPF, yeah it is pretty simple. For Winforms, make your own control that overrides OnPaint and OnPaintBackground appropriately. Here's something that I've used once or twice. Credit to Rick Strahl for C# version at http://www.west-wind.com/WebLog/posts/247977.aspx

Imports System
Imports System.Drawing
Imports System.Windows.Forms

' &lt;summary&gt;
' A label that can be transparent.
' &lt;/summary&gt;
Public Class TransparentLabel
    Inherits Control
    ' &lt;summary&gt;
    ' Creates a new "TransparentLabel" instance.
    ' &lt;/summary&gt;
    Public Sub New()
        TabStop = False
        Dim transparencyValue As Integer = 15 '0 is all transparent, 255 is solid
        ForeColor = Color.FromArgb(transparencyValue, ForeColor.R, ForeColor.G, ForeColor.B)
    End Sub

    ' &lt;summary&gt;
    ' Gets the creation parameters.
    ' &lt;/summary&gt;
    Protected Overrides ReadOnly Property CreateParams() As CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ExStyle = cp.ExStyle Or &amp;H20
            Return cp
        End Get
    End Property

    ' &lt;summary&gt;
    ' Paints the background.
    ' &lt;/summary&gt;
    ' &lt;param name="e"&gt;E.&lt;/param&gt;
    Protected Overrides Sub OnPaintBackground(ByVal e As PaintEventArgs)
        ' do nothing
    End Sub

    ' &lt;summary&gt;
    ' Paints the control.
    ' &lt;/summary&gt;
    ' &lt;param name="e"&gt;E.&lt;/param&gt;
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Using brush As SolidBrush = New SolidBrush(ForeColor)
            e.Graphics.DrawString(Text, Font, brush, -1, 0)
        End Using
    End Sub

End Class

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Visual Studio finally gets long-awaited feature that developers will love by Usama Jawad Visual Studio Code is Microsoft's popular, lightweight, open-source code editor, it is actually Visual Studio that is the company's flagship integrated development environment (IDE). Although the IDE already offers a boatload of useful features for developers, Microsoft has finally introduced a long-requested capability that will be loved by many. While developers have already been able to create Git pull requests (PRs) directly within Visual Studio for the past couple of years, it had not been possible to review a PR without switching to the browser, until now. Microsoft revealed in December 2025 that it is working on UX that enables developers to do just that, and fast-forward to June 2026, and Visual Studio finally has native capabilities to open and inspect a PR, discuss feedback, and wrap up the review, all without switching to the browser. This integration works for both GitHub and Azure DevOps (including on-prem). Developers have access to multiple surfaces to open a PR, including Git Repository, Git Changes, and the Git menu in Visual Studio. Once you open a PR, all the important details will be immediately visible to you, from where you can navigate to various levels of granularity and branch states, depending on the reviews that you are engaged in. As you would expect, you also get a diff view that enables you to see code changes inline or side-by-side in a separate panel. You can also review commit-by-commit. Additionally, this UX fosters collaboration as you can leave comments, reply to threads, and resolve conversations easily. Naturally, you can also leverage Copilot to apply a code suggestion to fix a potential issue. When you are done, you have the ability to approve, complete, and merge the PR. This is a pretty major feature as it has been requested heavily for the past few years. You can try it out in Visual Studio 2026 version 18.7, made available here recently. Microsoft plans to enhance this experience further in future releases with comment filtering, a timeline of PR activity, and more.
    • This AdGuard Family lifetime deal is still only $15.97 by Steven Parker Today's highlighted Neowin Deal comes via our Apps + Software section, where you can get a lifetime subscription and save 90% on a lifetime AdGuard Family Plan. AdGuard is a unique program that has all the necessary features for what they claim to be "the best web experience." The software combines the an advanced ad blocker, a privacy protection module, and a parental control tool—all working in one app. This software deals with annoying ads, hides your data from a multitude of trackers, protects you from malware attacks, and even lets you restrict your kids from accessing inappropriate content. Install AdGuard and see the internet as it was supposed to be: clean and safe. Get rid of annoying banners, pop-ups & video ads once and for all Hide your data from the multitude of trackers & activity analyzers that swarm the web Avoid fraudulent and phishing website and malware attacks Protect your kids online by restricting them from accessing inappropriate & adult content Good to know Family Plan Length of access: lifetime This plan is only available to new users Redemption deadline: redeem your code within 30 days of purchase Max number of devices: 9 Access options: desktop & mobile Software version: AdGuard Family Updates included A lifetime subscription of AdGuard Family Plan normally costs $169.99, but this deal can be yours for just $15.97, that's a saving of $157.02. For full terms, specifications, and license info please click the link below. Get this AdGuard Family lifetime deal for just $15.97 (was $169.99) Although priced in U.S. dollars, this deal is available for digital purchase worldwide. As an online publication, Neowin too relies on ads for operating costs and, if you use an ad blocker, we'd appreciate being whitelisted. In addition, we have an ad-free subscription for $28 a year, which is another way to show support! Support queries If you have queries or need support for any of the Neowin Deals, please use the contact form here. Neowin Deals are managed and sold by StackCommerce who represent Neowin on an affiliate basis. Why we post these deals We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. So for those that keep moaning and complaining, be thankful we're still online for you to even do that. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
    • the MCT currently downloads 26200.8653, so not completely up to date.
    • Around 68% of developers are now using AI to generate code during development, and some experts are saying that a single developer using AI tools can now do the work of an entire team of 4 to 5 engineers.  According to Figma's State of the Designer 2026 report, 72% of designers now use generative AI in their workflows and 91% say it improves the quality of their work, not just their speed.  But does this mean web developers and designers are becoming less relevant, or are they simply evolving into a different kind of role? Would love to hear from developers and designers here has AI made your job easier, or do you feel threatened by how fast these tools are improving
  • Recent Achievements

    • Week One Done
      Timaximus earned a badge
      Week One Done
    • One Month Later
      Timaximus earned a badge
      One Month Later
    • Rookie
      FBSPL went up a rank
      Rookie
    • First Post
      davidbazooked earned a badge
      First Post
    • Week One Done
      davidbazooked earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      508
    2. 2
      PsYcHoKiLLa
      181
    3. 3
      +Edouard
      160
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!