Click here to Skip to main content
15,346,659 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have many windows in my project... How can i do this...

I want to close the form when i press the ESC button.. but i dont want to writw this in all the windows.

I just want to write in a single place and when ever a user calls a ESC button the active window should be close...

Add a button with the property IsCancel = true. If you press ESCAPE the form closes.
Subclass a Windows Form.
Catch the keypress event and check for the ESC key or add a button as described above.
Inherit all your forms from this new Form instead of the standard Windows Form.

Change MyForm : Form


MyForm : SubclassedForm
Kishore Jangid 6-Oct-11 13:29pm
I asked this in WPF
ricmil42 6-Oct-11 14:16pm
Sorry, didn't see WPF in the "See more" section.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900