Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KeyPress\Up\Down doesn't work - C#

I have this code:

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
    MessageBox.Show("Fail!");
}


And I've set the event in the Form - but it simply isn't activated.
Other events like Resize or MouseDown work well, only this doesn't work.

Did someone ever experience this problem? What can I do ? [NO button works, neither characters or numerical or whatever].

Thanks, Mark!

like image 593
Mark Segal Avatar asked Oct 09 '11 17:10

Mark Segal


2 Answers

Dis you set theForm1.KeyPreview = true for more info visit http://msdn.microsoft.com/en-us/library/system.windows.forms.form.keypreview%28v=VS.80%29.aspx

like image 151
esunar Avatar answered Nov 19 '22 01:11

esunar


i think you have set like this..

 KeyPreview property set to true

and try this.....

int _i = 0;
private void Form1_KeyDown(object sender, KeyEventArgs e) {
    if (e.KeyCode == Keys.Escape) {
        label1.Text = (++_i).ToString();
    }
}
like image 3
Glory Raj Avatar answered Nov 19 '22 02:11

Glory Raj