Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KeyUp event on form wont run? c#

Tags:

c#

I wonder why this code never runs when I release a key.

    private void Form1_KeyUp(object sender, KeyEventArgs e)
    {
        MessageBox.Show("It works!");
    }

In designer this code is added as usual:

this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.Form1_KeyUp);

However events like Form load works perfect. Is there any common solutions for this problem?

like image 267
Danode Avatar asked Oct 06 '10 13:10

Danode


2 Answers

You should set the KeyPreview property of the form to true, this should work with your code.

like image 168
Aykut Çevik Avatar answered Nov 12 '22 10:11

Aykut Çevik


If the form has other controls on it try setting the Form.KeyPreview property to true: Key Preview on MSDN

like image 45
Darren Lewis Avatar answered Nov 12 '22 11:11

Darren Lewis