vb.net 如何捕获 Enter 按钮按下事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5830747/
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 capture Enter Button Pressed Event
提问by Failed_Noob
The image below shows a part of my Login form . The program works fine and I am able to login when I press the Enter Button. But I want to Login when I press My Enter Button (Return Button) on my Keyboard. How can I do this ?
下图显示了我的登录表单的一部分。该程序运行良好,当我按下 Enter 按钮时我可以登录。但是我想在按下键盘上的输入按钮(返回按钮)时登录。我怎样才能做到这一点 ?
回答by Sai Kalyan Kumar Akshinthala
In the properties of the form set the Accept button property
to the Enter button which will gives your desired.
在表单的属性中,将 设置Accept button property
为 Enter 按钮,这将提供您想要的。
回答by Dennis R?ttger
Try using
尝试使用
Me.AcceptButton = YourButton
YourButton.DialogResult = System.Windows.Forms.DialogResult.OK
pressing Return (on your Keyboard) will cause this Button_Click event to fire.
按 Return (在您的键盘上)将导致此 Button_Click 事件触发。
回答by Tim Schmelter
You could set the Form's AcceptButtonto your Enter-Button. Additionally you could set it's CancelButton to your Clear-Button. That calls the clear-function to be triggered when user presses Esc-Key.
您可以将 Form 的AcceptButton设置为Enter-Button。此外,您可以将它的 CancelButton 设置为您的清除按钮。当用户按下 Esc 键时,它会调用要触发的清除功能。
By the way, this was asked before here.
顺便说一句,这是在这里之前问过的。
回答by user3577412
Private Sub frmcalculator_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Enter Then
Call btnequals_Click(sender, e)
End If