天天看點

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