vb.net 文本框只能输入数字和退格键

 Private Sub TextBox_ComputerID_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox_ComputerID.KeyPress
     
        If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
            Me.Button_Search.Focus()
        End If
        Dim strlimit As String
        strlimit = "0123456789"
        Dim keychar As Char = e.KeyChar
        If InStr(strlimit, keychar) <> 0 Or e.KeyChar = Microsoft.VisualBasic.ChrW(8) Then
            e.Handled = False
        Else
            e.Handled = True
        End If
       
    End Sub 

你可能感兴趣的:(vb.net 文本框只能输入数字和退格键)