Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET C#4.0 WinForm
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 8-Jul-13 8:06am
Rate this: bad
good
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()[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You could try the Leave event
 
 private void txtTranUser1_Leave(object sender, EventArgs e)
        {
            this.txtTranUser1.Focus();
        }
  Permalink  
Comments
prathameshpitale at 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 at 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 at 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 at 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 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2014
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