A little while ago I developed a nice little “loading form class”. It basically consists of a sub which initializes a separate thread which is used to run a borderless form with a loading animation on it. You say:
LoadingForm.Show(Owner As Control)
And it does all the multithreading behind the scenes, then you sub continues until you call:
At which point the thread is terminated and the form is closed.
Anyway, I want to take advantage of this little async form in the following way. What if someone wants to cancel the process which his “loading” midway? I already set up a property in my LoadingForm called EscapePressed, which should be set to True if the escape key has been pressed at any time since “LoadingForm.Show” was called.
My problem is that I’m not sure how to catch the escape key-press. Since this form is being run on a separate thread, it doesn’t operate as part of the windows forms hierarchy (i.e. the main for opens a dialog form which opens another dialog form, etc). I’m simulating the modal dialog box behavior by passing the control through the “Show” method which should be treated as the LoadingForm’s “parent form”. Meaning the loading form is positioned over that particular control.
I’ve tried catching the KeyUp event of the LoadingForm itself, the “parent control” and the “parent form” (as retrieved by using the parent control’s FindForm function). Even with all this I can’t seem to capture the key press 100% of the time.
I know this may not be possible (it’s a bit of a streatch), but I’d like to know the following:
1. Is there a way I can capture the KeyUp event for every control/form in the entire application?
2. is there a way I can keep this LoadingForm on top of every other form in the application (the way Form.TopMost does it) and can I do that without stealing focus from other application which may be running?
3. Is there a better way to do all this?
Any help would be good.