Form uses event Form1_KeyDown , press the up and down keys on the keyboard do not respond.
Because Tab, Return, Esc and the up key, down key, left key and the right key is a pretreatment of these, when not used directly.
1 private void Form1_KeyDown(object sender, KeyEventArgs e) 2 { 3 //Keys NowKeys = Keys.Right; 4 this.NowKeys = e.KeyCode; 5 }
Like when doing the above, there will be no reaction.
This time need to use e.IsInputKey = true; this property;
The Properties button there, that is to say not take effect until the button is pressed.
1 private void Button1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) 2 { 3 e.IsInputKey = true; 4 }
Now you need to set the form's KeyPreview property to True.
More than ready to use.
There is another solution, which is the following:
. 1 /// <Summary> 2 /// override the default handling system keys, direction keys encountered, the process directly returns, not processed, so that the key will be transferred to the form, the trigger event KeyDown 3 /// </ Summary> . 4 /// <param name = "the keyCode"> </ param> . 5 /// <Returns> </ Returns> . 6 protected the override BOOL the ProcessDialogKey (Keys the keyCode) . 7 { . 8 IF (the keyCode == Keys. || || the keyCode == Keys.Down Up the keyCode == Keys.Left || the keyCode == Keys.Right) . 9 return to false ; 10 the else . 11 return Base .ProcessDialogKey (the keyCode); 12 is }
This part of the code directly copied to the program which you can, do not need any special treatment.