我的 WinForm 上有一个确定按钮。
我想提供点击确定按钮的选项,也可以通过输入按。
这是我的代码:
void MyFormKeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar==13)
{
//What have I to do in order to call ButtonOK click event?
}
}
谢谢
最佳答案
您可以设置 Form.AcceptButton按钮的表单属性。
This property enables you to designate a default action to occur when the user presses the ENTER key in your application. The button assigned to this property must be an IButtonControl that is on the current form or located within a container on the current form.
例子:
那么你的表单名称是form1,你的按钮是button1
form1.AcceptButton = button1;
应该做你想做的。
或者您可以使用您现有的代码并调用
yourButton.PerformClick();
关于c# - KeyPressed 事件调用其他事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21304741/