如何在 vb.net 中使用 ASCII 码输入
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30287943/
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
How to use ASCII code for Enter in vb.net
提问by Iki
I am having a little problem getting my code to do what I want.
我在让我的代码做我想做的事情时遇到了一些问题。
I want to prevent the user from using the Enter button when he/she is entering text into a text. The code I am using is:
我想阻止用户在他/她在文本中输入文本时使用 Enter 按钮。我正在使用的代码是:
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) = 13 Then
e.Handled = False
Else
e.Handled = True
MsgBox("Error.")
End If
End Sub
This not achieving my objective. Please how can I re-write this?
这没有达到我的目标。请问这个怎么改写?
回答by PaulAd
I agree with Tim3880. You are indeed keeping the user from entering anything with his/her keyboard; except the enter value. Your code is okay; only wrongly arranged, friend.
我同意 Tim3880。您确实在阻止用户使用他/她的键盘输入任何内容;除了输入值。你的代码没问题;只是安排错了,朋友。
Try this:
尝试这个:
Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) = 13 Then
e.Handled = True
MsgBox("Error.")
Else
e.Handled = False
End If
End Sub

