如何防止用户输入字符但只输入数字和“。”在 vb.net 2005 的文本框中?
最佳答案
以下将允许您测试特定的键值(来自 http://www.daniweb.com/forums/thread127299.html ):
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _
Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
e.Handled = True
End If
If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
e.Handled = False
End If
End Sub
如果这不是您要找的,请尝试
isNumeric()
功能。
关于vb.net - 如何允许用户在 vb.net 的文本框中只输入数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3413708/