phadaphunk
phadaphunk

Reputation: 13303

Tooltip showing twice

I'm showing a ToolTip on a certain button's MouseHover event. If I go over it once it works but if I leave, wait for the tooltip to disapear and come back on the button, it appears twice. I tried cancelling it on MouseLeave but it still appear twice the seocnd time.

Private Sub someButton_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles someButton.MouseHover

   Dim tooltipSearch As New ToolTip()
   tooltipSearch.Show("I'm a tooltip"), someButton)

End Sub

 Private Sub someButton_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles someButton.MouseLeave

    Dim toolTip As New ToolTip()
    toolTip.GetToolTip(someButton)
    toolTip.Hide(someButton)
    toolTip.Dispose()

End Sub

Am I missing something obvious?

Upvotes: 1

Views: 2394

Answers (3)

Chris Arbogast
Chris Arbogast

Reputation: 123

The answer about dragging the ToolTip control to the form is great. There is a subtlety with Button controls though. They seem to automatically set the tool tip to the text of the button, so if you also call ToolTip1.SetToolTip(myButton, "Button Text") then dot-net draws two copies of the tool tip text when you hover over the button.

Upvotes: 0

Steve Chamba
Steve Chamba

Reputation: 1

Private Sub someButton_MouseHover(sender As Object, e As System.EventArgs) _
                                  Handles someButton.MouseHover
  ToolTip1.SetToolTip(someButton, "My name is Steve chamba from south Africa")
End Sub

Upvotes: 0

Styxxy
Styxxy

Reputation: 7517

You are using the ToolTip not in the way it should be used (also look at the documentation :) ). It is just like any other control, start by dragging it onto your form (like you do with other controls).

If you have no dynamic text to be displayed in your tooltip, you can easily set the text in your constructor, using the method SetToolTip. If you do want some dynamic text, you can use this method in your MouseHover event.

Apart from that, you shouldn't do anything anything else. Just set the right delays on your tooltip and it should work all fine.

Upvotes: 1

Related Questions