简体   繁体   中英

Catch KeyUp Event on WinForm C#

I attempt to catch F5 on System.Windows.Forms for that I wrote:

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 ?

The KeyPreview property of the Form must be set to true.

When this property is set to true, the form will receive all KeyPress, KeyDown, and KeyUp events. After the form's event handlers have completed processing the keystroke, the keystroke is then assigned to the control with focus.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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