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.
You are competing Big Time over the Escape key. Along with the Enter key, that's a very important key in the standard Windows user interface. Just drop a button on form and set the form's CancelButton property to some other button, that will suck the keystroke to that button.
To compete with that, you have to create a control that tells Winforms that you really think that the Escape key is more important. That requires overriding the IsInputKey property. Like this: