• 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

    • Ah so it's not in the .ISO it's self but it changes the definition in the OOBE update during setup?
    • They always have. This just updates what's included out of the box during the initial install.
    • So basically their prebuilding it into the ISOs?
    • Microsoft shares Defender anti-virus update for new Windows 11/10 ISOs by Sayan Sen Following the one for Lumma last month, Microsoft has also published a new Defender update for Windows 11/10/Server installation images this month. This update package is necessary as a Windows installation image may contain old, outdated anti-malware definitions and software binaries. Aside from better security, these updates can also provide improved performance benefits in some cases. When a new Windows installation is set up, there may be a temporary security risk due to outdated Microsoft Defender protection in the OS installation images. This happens because the antimalware software included in these images might not be up to date. Thus Microsoft says that these updated definitions essentially help close this protection gap. Microsoft delivered the latest security definitions for Windows images via security intelligence update version 1.431.54.0. The Defender package version is also the same. It applies to Windows 11, Windows 10 (Enterprise, Pro, and Home editions), Windows Server 2022, Windows Server 2019, and Windows Server 2016. Microsoft writes: From Microsoft's security bulletin, we learn that the security intelligence update version 1.431.54.0 was released this past week adds threat detections for various backdoor exploits, trojans, among others. For those wondering, the latest intelligence update is version 1.431.155.0 at the time of writing.
    • “In other news about OneDrive frustration, Microsoft recently locked out a user who was attempting to move a bunch of important data from old hard drives to OneDrive.” - It was probably CSMA..
  • Recent Achievements

    • One Month Later
      SekTheFirst earned a badge
      One Month Later
    • First Post
      zayanhani earned a badge
      First Post
    • First Post
      HarryTaylor earned a badge
      First Post
    • One Year In
      Eternal Tech earned a badge
      One Year In
    • One Month Later
      Eternal Tech earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      649
    2. 2
      ATLien_0
      226
    3. 3
      Michael Scrip
      224
    4. 4
      Steven P.
      141
    5. 5
      +FloatingFatMan
      139
  • Tell a friend

    Love Neowin? Tell a friend!