vb.netwinformsvisual-studiotooltipballoon-tip

Why are balloon tip position and stem orientation buggy?


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:

  1. In Visual Studio, in design mode, drag a text box and tooltip onto a fresh form.
  2. 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

Solution

  • 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