2 Options:
1. In your Forms designer or in your code, set the
Form.CancelButton
property to your "Cancel" button. Then, when the Cancel button is pressed, or the Escape key is clicked (or even if the Dialog is closed) then the DialogResult of the form will be "DialogResult.Cancel."
2. Use keyDown event and trap KeyCode:
Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.Escape Then Me.Close()
End Sub
Try!