vb.net 在按钮上按回车键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18585855/
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
vb.net enter key press on a button
提问by bharathivkmani
I have a form with a button and when i click TAB key the button got selected but when I click ENTER key this code is not executed.My code is,
我有一个带有按钮的表单,当我单击 TAB 键时,按钮被选中,但是当我单击 ENTER 键时,此代码不会执行。我的代码是,
Private Sub Button1_Keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress
If Asc(e.KeyChar) = 13 Then
MsgBox("DO SOMETHING")
End If
End Sub
回答by Nadeem_MK
I don't think you have anything to code..
If your focus is on a button and you press ENTER, the Button1_Clickevent will fire..
我不认为你有什么要编码的..如果你的焦点在一个按钮上并且你按下回车键,Button1_Click事件就会触发..
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MsgBox("DO SOMETHING")
End Sub
That's the case if your focus is on the button. And if ever you wish to fire your event wherever your focus is, the your code should be fitted in the Form1_KeyPress() event
如果您的注意力集中在按钮上,就是这种情况。如果您希望在您的焦点所在的任何地方触发您的事件,您的代码应该安装在 Form1_KeyPress() 事件中

