我需要在文本框中控制用户的输入,那么我该怎么做? 谢谢
答案 0 :(得分:0)
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 AndAlso Not IsNumeric(e.KeyChar) Then
MessageBox.Show("Please enter numbers only")
e.Handled = True
End If
End Sub
已经问过同样的问题
How to allow user to enter only numbers in a textbox in vb.net?
答案 1 :(得分:0)
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If