views:

84

answers:

2

Is it possible to take focus from another program to respond to an event, but then once the response has been handled, switch back to the previous program and restore the cursor where it was?

This sounds like a weird question, but think of it along the lines of

  1. User is typing in a text box in Program A.
  2. A window for Program B pops up and user presses a few buttons to confirm something.
  3. Program B returns control to Program A and restores the selection of the textbox.

If there is a complete C# solution, then great, but this sounds like it might require a little more effort than usual.

Any thoughts?

+1  A: 

Personally, doing this could very likely result in the user selecting undesired values in the popup window. For example, someone is typing away in Word. Your application pops up a window, where hitting "Enter" selects a value ... such as the default button. Without wanting to, the user "selected" an incorrect value on your form.

Windows itself tends to do this, and it's very annoying. Quickly double-clicking a desktop shortcut to open an application and then switching back to (for example) an e-mail before the app launches, will tend to remove focus from the focused e-mail window and put focus in the just-opened application, causing your e-mail text or keyboard strokes to go to the just-opened window.

HardCode
+1  A: 

In my experience windows programs work just this way. It often appears that they don't because the user is returning focus with a mouse-click, which itself resets the focus. If it's a winforms app you can probably do something with the lost focus/got focus events at the form level.

Robert