简体   繁体   English

在WinForm C#上捕获KeyUp事件

[英]Catch KeyUp Event on WinForm C#

I attempt to catch F5 on System.Windows.Forms for that I wrote: 我尝试在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();
        }
    }
}

But my event catching looks not working. 但我的事件捕捉看起来不起作用。

Do you know how to cactch EventKey on System.Windows.Forms ? 你知道怎么在System.Windows.Forms上cactch EventKey吗?

The KeyPreview property of the Form must be set to true. Form的KeyPreview属性必须设置为true。

When this property is set to true, the form will receive all KeyPress, KeyDown, and KeyUp events. 当此属性设置为true时,表单将接收所有KeyPress,KeyDown和KeyUp事件。 After the form's event handlers have completed processing the keystroke, the keystroke is then assigned to the control with focus. 在表单的事件处理程序完成键击处理之后,然后将键击分配给具有焦点的控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM