All Things Techie With Huge, Unstructured, Intuitive Leaps

Killing Application With Escape Key in .NET C#

So, you are a C# weenie and you want to kill your Forms Application by hitting the escape key.  It's as easy as pie.

In the forms load method, put in the following two lines:

this.KeyPreview = true;
this.KeyDown += new KeyEventHandler(Form1_KeyDown);

Then create the KeyDown method:

private void Form1_KeyDown(object sender, KeyEventArgs e)
             if (e.KeyCode == Keys.Escape)

Hope this helps.

No comments:

Post a Comment