Solved

Exit when ESC is pressed

Posted on 2006-11-05
4
572 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
Comment Utility
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
Comment Utility
OK. So I will make a hidden button and test it.
0
 
LVL 2

Expert Comment

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

Expert Comment

by:DEEPESH
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

744 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

8 Experts available now in Live!

Get 1:1 Help Now