How to set limit values textbox and show message box when reached maximum limit VB.Net
抱歉英语不好。
我是VB.NET的初学者,在这个问题上,我想进行文本框验证,以便在达到最大限制时显示消息框。下面这个代码
1 2 3 4 5 6 7 8 9 10 11 12 | Public Class Form1 Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged Dim i As Integer TextBox1.MaxLength = 6 i = TextBox1.MaxLength If TextBox1.Text.Length > i Then MsgBox("Maximum is 6 Character") End If End Sub End Class |
表单加载事件设置
1 2 3 | Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load TextBox1.MaxLength = 6 End Sub |
在
1 2 3 4 5 6 7 |
或
保留
1 2 3 4 5 6 |