如何设置热键为Windows窗体形式 [英] How to set hotkeys for a Windows Forms form
本文介绍了如何设置热键为Windows窗体形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想设置热键在我的Windows窗体形式。例如,<大骨节病>控制骨节病> + <大骨节病> N 骨节病>新的形式和<大骨节病>控制骨节病> + <大骨节病>取值骨节病>对于保存。我将如何做到这一点?
I would like to set hotkeys in my Windows Forms form. For example, Ctrl + N for a new form and Ctrl + S for save. How would I do this?
推荐答案
设置
myForm.KeyPreview = true;
创建的处理程序的 <一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keydown%28v=vs.110%29.aspx"相对=nofollow>的KeyDown 的事件:
Create a handler for the KeyDown event:
myForm.KeyDown += new KeyEventHandler(Form_KeyDown);
处理程序的示例:
Example of handler:
// Hot keys handler
void Form_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.S) // Ctrl-S Save
{
// Do what you want here
e.SuppressKeyPress = true; // Stops bing! Also sets handled which stop event bubbling
}
}
这篇关于如何设置热键为Windows窗体形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文