How to close a form (WinForms) when Escape (Esc) key is pressed in C#

1 Answer

0 votes
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

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


answered Feb 8, 2015 by avibootz
...