Solved

Exit when ESC is pressed

Posted on 2006-11-05
4
578 Views
Last Modified: 2008-01-09
I have a pair of questions, but I think the answer to both is similar:

1) I have a window with several textboxes and buttons. I want the window to close (and the program to end) when the ESC button is pressed. Currently, I'm adding a KeyPress event to all controls, checking if the pressed button is ESC, which is not the wisest method! I hope there is a way to tell the window (or the Panel in which all those textboxes and buttons are located) to check each keypress. Is it possible?

2) In the same window, when the user presses ENTER button, no matter which textbox has the focus, I want a default button to be pressed (I mean, I want to call the SUB which handles the Press event of the default button.) Is this possible as well?

Please advice
Huji
0
Comment
Question by:huji
4 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 400 total points
ID: 17877067
See Form.CancelButton Property and Form.AcceptButton properties - they do exactly what you need.
To close form by Esc add Close button and write Me.Close in this button handler. Set Form's CancelButton Property to this button.
Set Form's AcceptButton Property to default button.
0
 
LVL 14

Author Comment

by:huji
ID: 17877333
OK. So I will make a hidden button and test it.
0
 
LVL 2

Expert Comment

by:x50Fade
ID: 17879215
Why do you want to hide it, all forms should theoretically have a "cancel" or "exit" button?
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17879396
Just like in VB6 you can make a default button which will be pressed when enter key is pressed anywhere in the form here you set AcceptButton property of the form you can select the button from the drop downlist which you want to be pressed on Enter key stroke and similarly for Esc button set cancelbutton .
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

864 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

22 Experts available now in Live!

Get 1:1 Help Now