Solved

Exit when ESC is pressed

Posted on 2006-11-05
4
580 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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