Question mousehover - form tooltip

a7v1n

New member
Joined
Dec 7, 2008
Messages
3
Programming Experience
1-3
hi. is there any way to display a form when the mouse is hovered inside a button? and then close the form when the mouse exits the button? how do you code this approach? thanks.
 
Handle the MouseHover and MouseLeave events of the Button. Show and Close/Hide the form.

That said, an owner drawn ToolTip may be better. What exactly do you want to display?
 
hi. i would like to show a form w/ an image and text when the user mousehover on a button. I'm still new to vb.net and dont know how to instantiate and display a form inside a form class. i was able to show a form using showmodelessdialog function on the module type of file. does it work the same way when mousehovering? Do i need to declare a variable as a form inside the mousehover function and then call the showmodelessdialog inside it? I tried it and it doesn't work. Thanks.
 
It will need some cleaning up to be usable but here's a proof of concept. Add a Button to a form and this code:
VB.NET:
Public Class Form1

    Dim f As Form

    Private Sub Button1_MouseHover(ByVal sender As Object, _
                                   ByVal e As EventArgs) Handles Button1.MouseHover
        If Me.f Is Nothing Then
            Me.f = New Form
            Me.f.StartPosition = FormStartPosition.Manual
            Me.f.Location = Control.MousePosition
            Me.f.Show()
        End If
    End Sub

    Private Sub Button1_MouseLeave(ByVal sender As Object, _
                                   ByVal e As EventArgs) Handles Button1.MouseLeave
        If Me.f IsNot Nothing Then
            Me.f.Close()
            Me.f = Nothing
        End If
    End Sub

End Class
I still say a custom drawn ToolTip is a better idea though.
 
Custom tooltip

hi. how do u do a custom tooltip? can it contain an image and a text at the same time? I am still new to vb.net thats why I still am not sure how to do things. Thanks a lot for the help.
 
ToolTip.OwnerDraw Property (System.Windows.Forms)

You use GDI+ to draw the ToolTip so you can draw anything that GDI+ supports. Try the example and then check out what other methods e.Graphics supports. I'll give you a clue: one of them is named "DrawImage". ;)
 
Back
Top