Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'How to check if text box max length has been exceeded?
- 'http://stackoverflow.com/questions/26534314/how-to-check-if-text-box-max-length-has-been-exceeded
- 'Corrected logic (full code using tooltips).
- 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) Then
- If TextBox1.Text.Length > 8 Then
- TextBox1.Text = TextBox1.Text.Substring(0, 8)
- TextBox1.Select(TextBox1.TextLength, 0)
- ToolTip1.IsBalloon = True
- ToolTip1.ToolTipTitle = "8 character maximum and input must be numeric!"
- ToolTip1.Active = True
- ToolTip1.ToolTipIcon = ToolTipIcon.Warning
- ToolTip1.Show(vbNewLine, TextBox1, 45, -40, 2000)
- ElseIf TextBox1.Text.Length > 0 Then
- If ToolTip1.GetToolTip(TextBox1) = "" Then
- ToolTip1.ToolTipTitle = "Input must be numeric!"
- ToolTip1.Active = True
- ToolTip1.IsBalloon = True
- ToolTip1.ToolTipIcon = ToolTipIcon.Warning
- ToolTip1.Show(vbNewLine, TextBox1, 45, -40, 2000)
- End If
- End If
- Else
- If TextBox1.Text.Length > 8 Then
- TextBox1.Text = TextBox1.Text.Substring(0, 8)
- TextBox1.Select(TextBox1.TextLength, 0)
- ToolTip1.IsBalloon = True
- ToolTip1.ToolTipTitle = "8 character maximum!"
- ToolTip1.Active = True
- ToolTip1.ToolTipIcon = ToolTipIcon.Warning
- ToolTip1.Show(vbNewLine, TextBox1, 45, -40, 2000)
- Else
- ToolTip1.Active = False
- ToolTip1.Hide(TextBox1)
- End If
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement