How do I close a form when the ESC key was hit, but only if no Control handled it?
Posted
by
Gabriel
on Stack Overflow
See other posts from Stack Overflow
or by Gabriel
Published on 2010-12-29T21:00:00Z
Indexed on
2010/12/29
21:54 UTC
Read the original article
Hit count: 239
I have a Form that closes itself when the ESC key is pressed, thanks to KeyPreview
, ProcessKeyEventArgs
, ProcessCmdKey
or whatever. But I have a Control on that form that does very relevant things when ESC is pressed (it hides itself) and the Form should not be closed when that happens.
The control uses the KeyDown
event and sets the SuppressKeyPress
flag to true, but that happens after the aforementioned form key preview, thus having no effect.
Is there some sort KeyPostview ?
How do I not close the form when a Control has a relevant use of a key hit ?
Edit: The control handling ESC is a textbox embedded in a hand-maid ListView. The textbox appears when the user clicks a cell, enabling edition. To validate the new text, ENTER would be nice (that already works, as giving the focus to anything else). To cancel edition, ESC seems most natural.
© Stack Overflow or respective owner