vb.net 显示文本框工具提示
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11543318/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Showing Textbox ToolTip
提问by bokshi
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.
我正在尝试在 vb.net 中的工具提示中工作。我想要做的是我在文本框控件中写的文本在工具提示中显示它。我可以在工具提示中显示文本,但我的问题是当我编辑输入文本时,它会在弹出工具提示中显示旧文本和新文本。这是我到目前为止所做的。
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.
谢谢你。
回答by LarsTech
It's hard to figure out why this is useful, but try using the TextChanged
event of the textbox to update the tooltip:
很难弄清楚为什么这很有用,但尝试使用TextChanged
文本框的事件来更新工具提示:
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