Reputation: 979
How could i make my Win app that when user press Esc. key and the App. going to close
Upvotes: 1
Views: 6471
Reputation: 45101
Set Form.KeyPreview = true
and add an event handler to Form.KeyDown
. Within this event handler add the following code:
if (e.KeyCode == Keys.Escape)
{
this.Close();
}
Upvotes: 7
Reputation: 36310
Edit: Changed my answer since you changed your question :-)
Add a close button to your form and set the CancelButton
property of your form to that button. Add code to the Button.Click
event handler that calls the forms Close
method.
Now you have a button that closes the form and when the user presses escape that button will be clicked.
Upvotes: 7