vb.net 只允许文本框中的数字值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29441899/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:57:24 来源:igfitidea点击:
Allow only numeric values in textbox?
提问by dba2015
I need to control the imputs of users in textbox so how I do that? Thank you
我需要控制用户在文本框中的输入,我该怎么做?谢谢
回答by Dino
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
Already Asked same questions Here
已经在这里问过同样的问题
How to allow user to enter only numbers in a textbox in vb.net?
回答by Mahadev
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If

