Showing Textbox ToolTip

一曲冷凌霜 提交于 2019-12-10 11:44:08

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/11543318/showing-textbox-tooltip

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!