CLOSE WINDOWS FORM ON CLICK ESCAPE KEY IN C#

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
C# 
C#
 4785  View(s)
Ratings:
Rate this:

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

  1. Jeet Verma

    Post:110

    Points:776
    Re: Close windows form on click escape key in C#

    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();
        }
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!