在大部分的Text文本限制只能输入数字的程序,是使键盘除了数字外的所有的按键失效的,可是这样做也会使得Microsoft Windows的快捷键也同时失效(例如:Ctrl+C或Ctrl+V).
下面我介绍的这个方法避免了这样的情况:
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim str As String = ""
Dim num As Integer = 0
Dim temp As String = ""
While num < TextBox1.Text.Length
temp += "[0-9]"
num += 1
End While
If Not (TextBox1.Text Like temp) Then
TextBox1.Text = str
TextBox1.Focus()
Else
Str = TextBox1.Text
End If
End Sub