huji
asked on
Exit when ESC is pressed
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Why do you want to hide it, all forms should theoretically have a "cancel" or "exit" button?
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 .
ASKER