C# · 12月 27, 2021

c# – 如何设置Windows窗体窗体的热键

我想在 Windows窗体窗体中设置热键.例如,Ctrl N为新窗体,Ctrl S为保存.我该怎么做?解决方法 组 myForm.KeyPreview = true;

为KeyDown事件创建一个处理程序:

myForm.KeyDown += new KeyEventHandler(Form_KeyDown);

处理程序示例:

// 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 other controls on the form receiving event. } }