Link to home
Start Free TrialLog in
Avatar of jackiemeck
jackiemeck

asked on

How to Enable ESC to close a dialog box in VB.net

I'm converting an old app to VB.Net and have many dialog boxes.  How do you enable the ESC key to close a dialog box?
ASKER CERTIFIED SOLUTION
Avatar of jppinto
jppinto
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"Set the DIALOG Form properties..."
you can also handle the keydown event to capture

    Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

        If e.KeyCode = Keys.Escape Then Me.Close()
    End Sub

Open in new window

Avatar of jackiemeck
jackiemeck

ASKER

I was unable to get the Subroutine to work (it appears sometimes my DataGridView captures the keypresses), but the AcceptButton/CancelButton solved my problem.  Thanks so much!!