To meet the project requirements, add the keyboard ESC response to the full screen Form. The effect is to press the Escape key on the keyboard in the full screen, and the program ends.
I thought it was quite simple, but it took a while to solve it. The procedure is summarized as follows:
First, add this. KeyPress + = new System. Windows. Forms. KeyPressEventHandler (this. Form_KeyPress) under the designer of form );
Then write the response function.
[Csharp]
Private void Form_KeyPress (object sender, KeyPressEventArgs e)
{
If (e. KeyChar = (char) Keys. Escape ){
Application. Exit ();
}
}
Private void Form_KeyPress (object sender, KeyPressEventArgs e)
{
If (e. KeyChar = (char) Keys. Escape ){
Application. Exit ();
}
}
After this is done, run the program and find that the form does not respond to ESC.
You also need to set the KeyPreview attribute to True in form ,:
After all, form responds to ESC normally.