Home > DeveloperSection > Forums > Catch KeyUp Event on WinForm C#
Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    September-04-2013 1:56 AM

 C# C# 
Ratings:


 1 Reply(s)
 1335  View(s)
Rate this:

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 ?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    September-04-2013 6:59 AM

Hi Jeet,

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.

Don't want to miss updates? Please click the below button!

Follow MindStick