Is it possible to cancel the "cancel-event" when pressing ESC in a dialog box?
Here's the situation:
I have a form where I have a cancel and Ok button (and of course lots of other non-important-for-this-case controls). This dialog box should be like any other dialog box, if you press ESC then the form closes and dialogresult should be Cancel. This part is easy, set the cancel button to have dialogresult cancel and the forms CancelButton property should point to this button
The problem is that I want the ESC key to do two different things, depending on situation. Under normal situations it should just close the form, but when I have a certain thread running on the form, I want the ESC key stop this thread (but still leave the form open)
The problem is that unfortunately MS has made it so that when the CancelButton is set on the form, the form closes after the code in the Cancel button has been fired. I haven't found any ways to stop the form from closing after ESC key has been pressed, being able to this would be the best solution IMHO
One solution to do what I want to do is this:
Remove the above mentioned CancelButton from the property on the form and handle the KeyDown Event to check for the ESC key, this gives me complete control. The negative side is that I pretty much need to handle the KeyDown Event on all controls on the form
Is my above mentioned solution the best way to do this? Or is there are way to stop the form from closing after ESC key has been pressed? Or is there some other much better solution I haven't thought about?