vikramaditya234
vikramaditya234

Reputation: 1398

form not getting proper focus in c#

i have written a small form application, which contains textbox only. I have enabled shortcut key by using low level keyboard hook to give focus to application when needed. All is working fine, I press the short key i.e. (Left Control Key)+(Left Control Key) for the first time the application get proper control (focus). But when I deactivate and redo the shortcut key, the icon of the application on the taskbar starts blinking and the form doesn't get focus, the title bar is greyed out.

More Information :

  1. on deactivation the form's opacity is reduced but it remains on top, so the whole time the form is displayed on the screen
  2. This form is activated from another class, within the application.
  3. On Activation event opacity of the form is increased so it now very well visible

I am giving focus to the application by using form.Activate() I have also tried from.Visible but with no luck. The activation works for the first time only, post that the icon in taskbar blinks.

Does any have any idea why is this happening?

Upvotes: 0

Views: 1436

Answers (1)

Dan Byström
Dan Byström

Reputation: 9244

This answer applies to you as well: https://stackoverflow.com/a/3789985/64121 . You need to make use of the AttachThreadInput API function in order to steal focus away from another app.

Upvotes: 1

Related Questions