事情的关键是要设置Form的KeyPreview属性,然后再在KeyDown事件中检查按键。

public class TEST : Form
{
public TEST()
{
InitializeComponent();
} private void TEST_Load(object sender, EventArgs e)
{
this.KeyPreview = true;
} private void TEST_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.F1 && e.Control)
{
MessageBox.Show("Hello!");
}
}
}

参考:http://www.cnblogs.com/Asa-Zhu/archive/2012/11/08/2761086.html

05-11 22:54