Click here to Skip to main content
13,089,433 members (59,309 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 8-Jul-13 7:06am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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()[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You could try the Leave event

private void txtTranUser1_Leave(object sender, EventArgs e)
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170813.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100