Friday, April 16, 2010

On Esc close the window

This concept always fascinated me. I always wondered how to do it in .NET. Then came the MSDN in rescue. So here I am sharing a tip to do it.

Step 1 : In the windows form there is a property KeyPreview make it to True . By default it is False.

Step 2 : In the KeyDown event of the form write this small code.

if (e.KeyCode == Keys.Escape)