• 0

VB.NET - setting label underline during runtime?


Question

I have VB.NET 2002, and I have a label that I'm using as a button (more customization), I want to change the underline property (to true) when the mouse is over it (either mouse hover. enter, or move - i don't know which is best to use), then cchange it back using the form's mouse over/hover/enter property. The problem is, when i try it, i get a read only error, seems the property is readonly. So how would I change it?

4 answers to this question

Recommended Posts

  • 0

You should specify that you're dealing with the Font of the Label, and not the Label itself... I was thinking, "There's no underline property for a Label." :o

The underline property of a Font is readonly. You could mimic it by drawing your own underline on the label itself, or use a LinkLabel as a button and have its behavior set to HoverUnderline.

You could also instantiate a new font of the same family and whatnot with the FontStyle set to Underline.

  • 0

To be more specific on the last suggestion:

   Private mThisFont As Font

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        mThisFont = New Font("Sans Serif", 12, FontStyle.Regular)
        Label1.Font = mThisFont
    End Sub

    Private Sub Label1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.MouseEnter
        mThisFont = New Font("Sans Serif", 12, FontStyle.Underline)
        Label1.Font.Dispose()
        Label1.Font = mThisFont
    End Sub

    Private Sub Label1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.MouseLeave
        mThisFont = New Font("Sans Serif", 12, FontStyle.Regular)
        Label1.Font.Dispose()
        Label1.Font = mThisFont
    End Sub

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

    • No registered users viewing this page.
  • Posts

    • Good Bye and thanks for the fish
    • yeah i did some research and it seems they removed (or didn't carry over) the ability to change desktop icon fonts.....hopefully they bring it back for you soon...and yeah it also seems the ability to change the font has also been removed unless you adjust through registry or win aero.    if you haven't already, maybe trying to "adjust cleartype text" may help you. i tried running through it and noticed there were some bold font styles.   welcome (or bye haha) to windows 2025 btw!  
    • That'll be it for my 2018 Mac mini then. There is, of course, OpenCore Legacy Patcher . . .
    • Support cost cutting and nudging people to upgrade for profit. Pure and simple. Nothing as noble as hardware actually becoming "obsolete" about most of the hardware requirements from Apple, Microsoft, or Android companies either. iMac 2017 with AMD running legacy Core still have native GPU support in macOS 15 and run perfectly fine. Doesn't even need any fancy patching outside of the minimum patching needed to get macOS 15 on the system to bypass Apple system requirements aking to running windows 11 on a PC that doesn't match the arbitrary CPU generation requirements that make you bypass them too. You can usually tell if hardware is truly in the realm of "obsolete" if you are having a hard time finding a major Linux distro that'll install on it.
    • >Mozilla's Firefox has been left behind over time in terms of market share, as it has not been able to keep up with Chromium-based browsers in the performance department. I have no problems with Firefox's performance whatsoever. I suspect the reason Firefox is lagging in market share is that average consumers haven't heard of it and are fine with what was installed on their systems.
  • Recent Achievements

    • Conversation Starter
      Naomi723 earned a badge
      Conversation Starter
    • Week One Done
      abortretryfail earned a badge
      Week One Done
    • First Post
      Mr bot earned a badge
      First Post
    • First Post
      Bkl211 earned a badge
      First Post
    • One Year In
      Mido gaber earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      486
    2. 2
      +FloatingFatMan
      256
    3. 3
      snowy owl
      243
    4. 4
      ATLien_0
      222
    5. 5
      +Edouard
      191
  • Tell a friend

    Love Neowin? Tell a friend!