Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 665
  • Last Modified:

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?
0
jackiemeck
Asked:
jackiemeck
  • 2
1 Solution
 
jppintoCommented:
Set the Form properties

AcceptButton=your searchbutton
CancelButton=your cancelbutton
0
 
jppintoCommented:
"Set the DIALOG Form properties..."
0
 
nepaluzCommented:
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

0
 
jackiemeckAuthor Commented:
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!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now