问题
My problem:
I'm using a balloon tip on a text box to indicate non-numeric entry (real-time). Once a second non-numeric character is inputted, the balloon tip position and stem orientation changes (inverts and undesirably
To reproduce:
- In Visual Studio, in design mode, drag a text box and tooltip onto a fresh form.
- Use the following as is:
Code:
Public Class Form1
Private Sub Textbox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
If (Not IsNumeric(TextBox1.Text) And TextBox1.Text.Length > 0) Then
ToolTip1.ToolTipTitle = "Input must be numeric!"
ToolTip1.Active = True
ToolTip1.IsBalloon = True
ToolTip1.Show(vbNewLine, TextBox1, 45, -40)
Else
ToolTip1.Active = False
ToolTip1.Hide(TextBox1)
End If
End Sub
End Class
回答1:
You can check if tooltip
is visible before showing it:
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
If (Not IsNumeric(TextBox1.Text) And TextBox1.Text.Length > 0) Then
If ToolTip1.GetToolTip(TextBox1) = "" Then
ToolTip1.ToolTipTitle = "Input must be numeric!"
ToolTip1.Active = True
ToolTip1.IsBalloon = True
ToolTip1.Show(vbNewLine, TextBox1, 45, -40)
End If
Else
ToolTip1.Active = False
ToolTip1.Hide(TextBox1)
End If
End Sub
来源:https://stackoverflow.com/questions/26528559/why-are-balloon-tip-position-and-stem-orientation-buggy