Solved

Loading form which captures key input

Posted on 2013-12-24
5
266 Views
Last Modified: 2014-01-22
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)

Open in new window

And it does all the multithreading behind the scenes, then you sub continues until you call:
LoadingForm.Hide()

Open in new window

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.
0
Comment
Question by:BROOKLYN1950
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 10

Expert Comment

by:Korbus
ID: 39738685
I guess I'm a bit confused why you would want escape to close the loading form even when the loadingform does not have the focus.
What if the user is typing something in an edit box and hits escape:  should this simply leave the edit box, or close the loading form?

It sounds like, though I may be misunderstanding, like the problem is due to the fact that the loadingform is not given the Focus when it's opened.  Giving it the Focus would ensure it's drawn on top, and handles keypresses.  Or perhaps the problem is giving the focus to the loading form, when switching back from a different app?
0
 

Author Comment

by:BROOKLYN1950
ID: 39739293
The problem is that since the loading form is on a separate thread, it does not behave like a child-form of the form that's calling it; meaning the user could click back onto the form and give other controls focus (take focus away from the loading form).
When this form is up, the user should be able to anything with the UI. Other than watch the loading GIF spin as background operations complete.
The point of this form is to have it manage the UI (by continuously calling Application.DoEvents) and check for the escape key press while the main form runs other code (calculations, SQL access, etc).
Really I'd like it if I could somehow stop any other control in MY application from getting focus while the form is up, while still allowing other users to switch their focus to other applications.
0
 
LVL 10

Expert Comment

by:Korbus
ID: 39739395
I see.  Perhaps you could use the "Activated" Event handler for your forms.  In there, check to see if the LoadForm is open (e.g LoadForm.IsRunning), and if so, give it the focus instead.
Do you have lots of forms that might be open at this time?
I would suspect there IS an event you can use, for when you app as a whole, is given the focus, but I have found it yet.
0
 

Accepted Solution

by:
BROOKLYN1950 earned 0 total points
ID: 39788810
Well, looks like no one else can figure out this one either. I guess that the way I'm doing it probably wont work. Time to go work-around hunting. Thanks anyways.
0
 

Author Closing Comment

by:BROOKLYN1950
ID: 39799472
I gave up on the question.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question