C # Window_KeyUp () not working

Hi, I have this piece of code:

private void Window_KeyUp(object sender, KeyEventArgs e) { if (playing == false) { return; } if (e.KeyCode == Keys.D1) { pictureBox6.Image = Form.Properties.Resources.black_square_button; player.Stop(); player.Close(); playing = false; } } 

I do not work, but Window_KeyDown () works.

What is wrong with my code?

Thanks.

+4
source share
1 answer

KeyUp events (also KeyDown and KeyPress) are triggered at the form level only if the form has

 KeyPreview = true; 

MSDN is here

true if the form receives all key events; false if the currently selected form control accepts key events. The default is false.

+13
source

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


All Articles