When you start the thread, set the form's CancelButton property to nothing, that'll prevent the form's closing code from running, next you'll need to use the form's KeyUp event to detect the escape key and if the thread's running, cancel it and reset the form's CancelButton property back to your cancel button.
Also when the thread completes successfully be sure to re-set the form's cancel button property to your button.
Pretty much what you've already concluded to, I'd just use the KeyUp event instead of KeyDown for Escape key checking.
__________________
Currently using: VS 2005 & 2008 Pro w/sp1 on Win7 Ultimate x64.

There are 3 kinds of people in the world: Those who can count and those who can't.
4 out of 3 people have trouble with fractions.
Windows has a 64 bit GUI for a set of 32 bit extensions on a 16 bit shell for an 8 bit OS using a 4 bit kernel made by a 2 bit company that can't stand 1 bit of competition.
|