Results 1 to 8 of 8

Thread: Popup message when mousehover a label

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    24

    Popup message when mousehover a label

    Hello everybody.

    I am new to VB and need some help.
    I have created some labels and i need them to display a popup message when you hover the mouse over them at runtime. I searched for a solution but i only found out how to display popups when hovering over a button and also the code for that was overly complicated. Any ideas?

    Thanks a lot.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Popup message when mousehover a label

    try this:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Dim tt As ToolTip
    4.  
    5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.         tt = New ToolTip
    7.         tt.SetToolTip(Label1, "message")
    8.     End Sub
    9.  
    10. End Class

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    24

    Re: Popup message when mousehover a label

    Wow thanks a lot. It worked, i only had to change the event to MouseHover..

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Popup message when mousehover a label

    Quote Originally Posted by 16horse View Post
    i only had to change the event to MouseHover..
    no need. it will work if you call settooltip in form_load + it'll only do it once, instead of every time your mouse hovers on the label

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    24

    Re: Popup message when mousehover a label

    Another question. Is there a way to create a module out of this code in order to display different messages when i hover over different label?So that i write the code once and use it for all the different labels and their individual popup messages.

  6. #6
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Popup message when mousehover a label

    16horse, all you need to do is add a ToolTip component to your form and you'll be able to set the ToolTip text on all the visual controls you want to on that form. There's no need for something like this to be ran through a module.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Popup message when mousehover a label

    it's simple to set a tooltip for any number of controls:

    vb Code:
    1. Public Class Form1
    2.  
    3.     'declare tooltip at form level
    4.     Dim tt As ToolTip
    5.  
    6.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7.         'initialize tt with 'New' keyword
    8.         tt = New ToolTip
    9.         'set tooltip for any control here
    10.         'don't put this in the mousehover event,
    11.         'or it'll keep running this code every time it fires
    12.         tt.SetToolTip(Label1, "message1")
    13.         tt.SetToolTip(Label2, "message2")
    14.     End Sub
    15.  
    16. End Class

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2010
    Posts
    24

    Re: Popup message when mousehover a label

    I managed to do it on my own, finally, but with a messier code than .paul. suggested. So i changed it with yours and it works.
    Thanks again soooo much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width