Solved

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

Posted on 2011-02-24
4
609 Views
Last Modified: 2012-05-11
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
Comment
Question by:jackiemeck
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
jppinto earned 500 total points
ID: 34974808
Set the Form properties

AcceptButton=your searchbutton
CancelButton=your cancelbutton
0
 
LVL 33

Expert Comment

by:jppinto
ID: 34974819
"Set the DIALOG Form properties..."
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 34974935
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
 

Author Comment

by:jackiemeck
ID: 34979696
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now