Click here to Skip to main content
11,921,316 members (61,916 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# .NET C#4.0
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 8: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
0 OriginalGriff 583
1 Dave Kreskowiak 245
2 phil.o 160
3 KrunalRohit 134
4 F-ES Sitecore 130
0 OriginalGriff 6,951
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,171
3 George Jonsson 2,840
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2015
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