Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Window_KeyUp() not working

Tags:

c#

keyup

Hey 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'ts not working but the Window_KeyDown() works.

What is wrong with my code?

Thanks.

like image 399
Joscplan Avatar asked Jun 02 '13 22:06

Joscplan


1 Answers

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

KeyPreview = true; 

MSDN here

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

like image 158
Steve Avatar answered Sep 20 '22 08:09

Steve