如何阻止用户输入字符,但只能输入数字和’.’在vb.net 2005的文本框中?
以下内容允许您测试特定的键值(从
http://www.daniweb.com/forums/thread127299.html开始):
原文链接:https://www.f2er.com/vb/255904.htmlPrivate 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()函数.