Home > DeveloperSection > Forums > Close windows form on click escape key in C#
Ashish Pandey

Total Post:128

Points:898
Posted on    October-07-2013 8:50 AM

 C# C# 
Ratings:


 1 Reply(s)
 3067  View(s)
Rate this:

How to close a windows form on click the escape key using C#?



Jeet Verma
Jeet Verma

Total Post:110

Points:776
Posted on    October-08-2013 1:06 AM

Firstly you need to handle the Form Key Down event and then check the event key code is equal to Keys.Escape and the in the true section you can write the form close statement.

private void Form_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Escape)
    {
        this.Close();
    }
}

Don't want to miss updates? Please click the below button!

Follow MindStick