Solved

Force focus in a windows form

Posted on 2011-02-18
5
551 Views
Last Modified: 2012-05-11
There are a windows form with some controls: datagridview, textboxes, labels, buttons. Operator use a scanner configurated in keyword emulator to read barcodes. If the focus of the cursor is not in the right place (dedicated textbox) the content is not processed and in some cases can cause errors. Fortunately barcode starts with a particular character ("*") so I've think to intercept * and force focus to the textbox but I don't know witch event can help me.
0
Comment
Question by:fantamen
  • 2
  • 2
5 Comments
 
LVL 10

Expert Comment

by:kdwood
ID: 34926057
fantamen,

Can you be more specific as to how your windows Form is called and how your application is designed.  It seems to me that you would force the focus to the proper input field prior to the scanning, as a part of the application design.  Instead, it seems as though you wish to force focus as a result of a barcode being scanned.

A step by step explanation of your process would help to understand your problem.

Regards,

Keith
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 250 total points
ID: 34926288
the form has a KeyPreview property. set it to true.

now handle the KeyPress event of the form. If you find your *, do a YourTextBoxControlName.Focus
0
 

Author Comment

by:fantamen
ID: 34926344
For example a barcode can be this: *045 02341
Keyboard emulator scanner read this code. If the active control of the form is txtBarCode all is ok. If operator has put the focus to a cell in a datagridview in the form and then read the barcode naturally *045 02341 is written in the cell and this is the problem. If I can intercept the first character of the barcode (*) and in presence of * force the focus to txtBarCode i will solve my problem.


0
 
LVL 10

Expert Comment

by:kdwood
ID: 34926381

So it seems that your form is not just used for scanning input, but has other interactive purposes.  In that case, I believe emoreau's solution should work.

Regards,

Keith
0
 

Author Comment

by:fantamen
ID: 34926904
Dear Emoreau and kdwood your suggestion solve my problem. Very good!
I've add two lines in then Form_KeyPress event, after txtBarCode.Focus, one to add at the beginning of the code the * and another to set the selection start to the second position in the text box.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now