Search code examples
vb.netwinformstooltip

Showing Textbox ToolTip


I am trying to work in the tooltip in vb.net. What I am trying to do is whatever I write the text in the textbox control show it in the tooltip. I am able to show text in tooltip but my question is when I edit input text it will show old and new text in the popup tooltip. Here is what I have done so far.

Public Class Form1
  Dim s As String = ""

  Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    s = TextBox1.Text
    Dim tooltip1 As System.Windows.Forms.ToolTip = New System.Windows.Forms.ToolTip()

    tooltip1.SetToolTip(Button1, s)
  End Sub
End Class

Thank you.


Solution

  • It's hard to figure out why this is useful, but try using the TextChanged event of the textbox to update the tooltip:

    Private _ToolTip As New ToolTip()
    
    Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As EventArgs) _
                                     Handles TextBox1.TextChanged
      _ToolTip.Show(TextBox1.Text, TextBox1)
    End Sub