Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,
I have created an bar-code reader application. There is window which awaits for input in the text box from bar-code reader and then process the i/p and display the success message in List-box.

All is working fine, but some time automatically the window looses focus (because of background/updating processes of OS) and the i/p from bar-code reader cannot reach the text-box causing a complete failure.

Is there any way, so that i can program that window to never loose focus?

SetForegroundWindow() can it help? how can i implement this?

help appreciated!
Posted

You can add a timer to the form and in Tick event set the form as a foreground window. SetForegroundWindow() is explained in the following post.

How to bring window to top with SetForegroundWindow()[^]
 
Share this answer
 
You could try the Leave event

C#
private void txtTranUser1_Leave(object sender, EventArgs e)
       {
           this.txtTranUser1.Focus();
       }
 
Share this answer
 
Comments
prathameshpitale 8-Jul-13 22:11pm    
No, its not that textbox looses focus. The complete window looses focus.
I have used the leave event. that helps when user try to change the focus.
Richard.Berry100 9-Jul-13 14:57pm    
Sincere apologies - I did not read your question properly. Just out of interest though, I've done some very similar apps, why does the WINDOW lose focus?
prathameshpitale 15-Jul-13 1:13am    
Suppose windows update process is running, and automatically a dialog pops out or any notification from OS or other application the windows looses focus.
Richard.Berry100 17-Jul-13 17:43pm    
I suppose something as setting the TopMost property of the form to true wont help?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900