• 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

    • Except Rolling Releases. No EOL, continuous updates.
    • True, Windows 95 could barely run on systems made in 1995. Two responses, first, people did complain in the 90s about how quickly software updates obsoleted hardware, so it isn't like it was fine then and not now. Second, it hits a little different when the requirement is seemingly arbitrary instead of a true resource requirement.
    • Go from ZERO to ADVANCED with this Microsoft Training Bundle + Office 2021 Pro Plus by Steven Parker Today's highlighted deal comes via our Online Courses section of the Neowin Deals store, where you can save 79% off Microsoft Office Pro Plus 2021 + Microsoft Training Bundle: ZERO to ADVANCED. This bundle consists of the following items: Microsoft Training Bundle: ZERO to ADVANCED LearningWhilePracticing | 6 Lessons (25h) | Lifetime $20.00 Value The Microsoft Training Bundle is the ultimate course for those looking to master Microsoft Office. With comprehensive lessons that cover Excel, Word, Access, and PowerPoint, you'll go from beginner to advanced user in no time. Learn in-demand skills like VLOOKUP and XLOOKUP in Excel, and conditional formatting to make your data stand out. With this bundle, you'll have all the tools you need to succeed in the workplace and beyond. Access 6 courses & 25 hours of content 24/7 Learn to create workbooks & spreadsheets Explore the readily available document templates Protect a file with a password & recover an unsaved document Build effective database solutions for unique data needs Create a PowerPoint presentation from scratch Create slides, textboxes & formatting text and paragraphs Perform two-dimensional lookups Discover how to calculate & highlight expiration dates What’s Included Microsoft Excel: from ZERO to ADVANCED Microsoft Word: from ZERO to ADVANCED Microsoft Access: from ZERO to ADVANCED Microsoft PowerPoint: from ZERO to ADVANCED VLOOKUP & XLOOKUP in Excel Conditional Formatting in Excel Good to know Length of time users can access this course: lifetime Access options: desktop & mobile Redemption deadline: redeem your code within 30 days of purchase Experience level required: beginner Updates included Certificate of Completion ONLY Microsoft Office Pro Plus 2021: Lifetime License One time digital license | $219.99 Value Everything a pro needs, all in one suite — that’s Microsoft Office 2021 Professional. Microsoft Office 2021 Professional is the perfect choice for any professional who needs to handle data and documents. It comes with many new features that will make you more productive in every stage of development, whether it’s processing paperwork or creating presentations from scratch – whatever your needs are! Good to know ONE-TIME PURCHASE FOR 1 PC Redemption deadline: redeem your code within 30 days of purchase This is NOT compatible with MS Office on Parallels Pro and other Virtual Machines Access options: desktop No subscriptions – no monthly/annual fees Version: Office 2021 Pro All languages supported Updates included Here's the deal: This Microsoft Office Pro Plus 2021 + Microsoft Training Bundle: ZERO to ADVANCE bundle normally costs $239.99, but you can get it for just $49.99 for a limited time - that's a saving of $189 or 79% off. For a full description, specs, and instructor info, click the link below. Get Office 2021 Pro + Office Training Bundle deal for just $49.99, or learn more Although priced in U.S. dollars, this deal is available for digital purchase worldwide. 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. 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.
    • This article is about older builds of Windows 11 losing support, there have been no system requirements changes for any version of Windows 11. You were probably talking about Windows 10...but that is a an off-topic comment.
    • Only if you install an LTS version. The non-LTS distros of Linux typically have much shorter support cycles than Windows. If you are the kind of person who, for whatever reason, doesn't want to move to newer builds, simply "install linux" would make it worse, not better.
  • Recent Achievements

    • Week One Done
      Stephen Leibowitz earned a badge
      Week One Done
    • Week One Done
      Homayoun Hotak earned a badge
      Week One Done
    • Dedicated
      Profit earned a badge
      Dedicated
    • One Month Later
      hhgygy earned a badge
      One Month Later
    • Week One Done
      hhgygy earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      640
    2. 2
      ATLien_0
      240
    3. 3
      Xenon
      169
    4. 4
      neufuse
      151
    5. 5
      +FloatingFatMan
      124
  • Tell a friend

    Love Neowin? Tell a friend!