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.
Re: Popup message when mousehover a label
try this:
vb Code:
Public Class Form1
Dim tt As ToolTip
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tt = New ToolTip
tt.SetToolTip(Label1, "message")
End Sub
End Class
Re: Popup message when mousehover a label
Wow thanks a lot. It worked, i only had to change the event to MouseHover..
Re: Popup message when mousehover a label
Quote:
Originally Posted by
16horse
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
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.
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.
Re: Popup message when mousehover a label
it's simple to set a tooltip for any number of controls:
vb Code:
Public Class Form1
'declare tooltip at form level
Dim tt As ToolTip
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'initialize tt with 'New' keyword
tt = New ToolTip
'set tooltip for any control here
'don't put this in the mousehover event,
'or it'll keep running this code every time it fires
tt.SetToolTip(Label1, "message1")
tt.SetToolTip(Label2, "message2")
End Sub
End Class
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.