fantamen
asked on
Force focus in a windows form
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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
ASKER
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.
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.
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