为什么气球尖端位置和茎杆定向车?

时间:2014-10-23 12:52:47

标签: vb.net winforms visual-studio tooltip balloon-tip

我的问题:

我在文本框中使用气球提示来指示非数字输入(实时)。一旦输入第二个非数字字符,气球尖端位置和杆方向就会改变(反转并且不合需要地

重现:

  1. 在Visual Studio中,在设计模式下,将文本框和工具提示拖到新表单上。
  2. 按原样使用以下内容:
  3. 代码:

    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 个答案:

答案 0 :(得分:1)

您可以在显示之前检查tooltip是否可见

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