954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

form not getting focus

hi,
i have written a small form application in c#. 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. LControlKey+LControlKey for the first time the application get proper control.
But when I deactivate and redo the shortcut key, the icon of the application on the taskbar starts blinking and textbox in the application seems to get the focus(cursor blinking) but the control is still not reached. I say this because when i try to write something nothing gets written on the application.

I am giving focus to the application by using form.Activate() I have also tried from.Visible but with no luck.
Does any have any idea why is this happening?

vikramaditya234
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

try form.focus() , may be this will work for you :)

Regards

waqasaslammmeo
Posting Pro in Training
472 posts since Aug 2011
Reputation Points: 38
Solved Threads: 82
 

I have tried that its not working.

Here is what i have tried:
1. I have one form class and another operation class. The object of the form class has been passed to the operation class.
2. The logic for implementation of shortcut key is in operation class and when the shortcut key is detected the object of form is used to activate the form.
3. Once form1.activate() is processed the event for form activated is triggered and the respective function is called from inside form class.
4. I have tried using form1.focus() from operation class and in form class both with no luck.
5. I even disabled all the controls present inside the form, but this also didnt help.

Trying all the above still gives the same output. That is, when the form is deactivated or minimized and the shortcut key is used for the 1st time, the form gets activated, with the change in the title bar. Now I take the form out of focus(deactivate or minimize) and again use shortcut key to activate the form, this time the form is not activated and the icon in the taskbar starts blinking.
The proper activation works only once, not after that.

vikramaditya234
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

form1.Activate()
form1.Focus()
form1.ActiveControl = form1.textBox1

NetDeveloper
Newbie Poster
5 posts since Feb 2012
Reputation Points: 10
Solved Threads: 1
 

this doesnt work.
however i received another response, which i am trying to implement:
http://stackoverflow.com/questions/9174661/form-not-getting-proper-focus-in-c-sharp

vikramaditya234
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: