Catch KeyUp Event in WinForm C #

I am trying to catch F5 on System.Windows.Forms for what 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 tracking does not work.

Do you know how to cactch EventKey on System.Windows.Forms ?

+8
source share
1 answer

The KeyPreview property of the form must be true.

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

+12
source

Source: https://habr.com/ru/post/953111/


All Articles