在WinForm C#上捕获KeyUp事件

我尝试在System.Windows.Forms上捕获F5,因为我写道:

 partial class MainForm { (...) this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.MainForm_KeyUp); (...) } public partial class MainForm : Form { (...) private void MainForm_KeyUp(object sender, KeyEventArgs e) { Log("MainForm_KeyUp"); if (e.KeyCode == Keys.F5) { RefreshStuff(); } } } 

但我的事件捕捉看起来不起作用。

你知道如何在System.Windows.Forms上cactch EventKey吗?

表单的keypreview属性必须设置为true

当此属性设置为true时,表单将接收所有KeyPress,KeyDown和KeyUp事件。 在表单的事件处理程序完成键击处理之后,然后将键击分配给具有焦点的控件。