I have tried the following:
private void Form1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if ((Keys) e.KeyValue == Keys.Escape)
Assuming that you have a "Cancel" button, setting the form's CancelButton property (either in the designer or in code) should take care of this automatically. Just place the code to close in the Click event of the button.
CancelButton
Click