gpt4 book ai didi

c# - KeyPressed 事件调用其他事件

转载 作者:太空宇宙 更新时间:2023-11-03 20:08:50 24 4
gpt4 key购买 nike

我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com