Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing ToolTip Text

Status
Not open for further replies.

Kliot

Programmer
Jan 10, 2003
622
US
What's the best way to change the ToolTip Text dynamically, for example If a TextBox.text = "A" I want the tooltip text to be "Apple", if it's "B" the tooltip should be "Banana."

The best I'v come up with is setting ToolTip1.SetToolTip(TextBox1, "Text") in the mouseHover event. This works but the tooltip flickers, it shows once then goes away then shows again. Is there a better way of doing this or how do I get rid of the flicker.

Thanks
 
TextChanged would probably work but would be less than ideal. My example was overly simple, I actually have to run a complex query to get the text value for the tooltip and I only want to run it if the tooltip is being called, that's why I went with the mousehover, my first thought was the tooltip1_popup but that gave me a stack overflow error.
 
Is the query returning more than one result? Is it contained in a loop?

Posting some sample code showing how you are doing this could help

-brian
 
I saw a bit of flickering too, until I tried this:
Code:
    Dim Hovering As Boolean
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ToolTip1.AutoPopDelay = 2000
        ToolTip1.InitialDelay = 1000
        ToolTip1.ReshowDelay = 500
        ToolTip1.ShowAlways = True
        ToolTip1.SetToolTip(Me.TextBox1, TextBox1.Text)
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        If Not Hovering Then
            Exit Sub
        End If
        ToolTip1.SetToolTip(Me.TextBox1, TextBox1.Text)
    End Sub

    Private Sub TextBox1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseHover
        ToolTip1.SetToolTip(Me.TextBox1, TextBox1.Text)
        Hovering = True
    End Sub

    Private Sub TextBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.MouseLeave
        Hovering = False
    End Sub
End Class
I'm just using MouseHover and MouseLeave to determine whether you're in the box or not, and then if so, using TextChanged to set the tooltip text. Perhaps something like that might work for you.

Bob
 
Brian,

I was just testing with very simple code and getting a flicker.

Bob,

Thanks for the suggestion, I'll try your settings.

Perrin
 
The popup event is cleaner, but we have the 1.1 framework at work, and it's not available until 2.0.
 
I originally tried to use the popup event but it gave me a stackoverflow error.
 
So you mentioned, but I can't test it as I don't have it avaialble at all. However, the most common cause of a stack overflow is a recursive procedure call endless loop. (The simplest way to create one is have proc a call proc b which in turn calls proc a.) You might be able to find such a thing somewhere if you dig around enough.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top