Solved

Exit when ESC is pressed

Posted on 2006-11-05
4
583 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

622 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