Windows窗体 - 输入按键激活提交按钮? [英] Windows Forms - Enter keypress activates submit button?

查看:132
本文介绍了Windows窗体 - 输入按键激活提交按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何能捕捉我的表上的任何地方输入按键,并迫使它触发提交按钮事件?

How can I capture enter keypresses anywhere on my form and force it to fire the submit button event?

推荐答案

如果您设置窗体的的AcceptButton属性窗体上的一个按钮,你会得到默认的行为。

If you set your Form's AcceptButton property to one of the Buttons on the Form, you'll get that behaviour by default.

否则,设置KeyPreview属性为True窗体上处理其KeyDown事件。您可以检查回车键,并采取必要的行动。

Otherwise, set the KeyPreview property to True on the Form and handle its KeyDown event. You can check for the Enter key and take the necessary action.

这篇关于Windows窗体 - 输入按键激活提交按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆