In C#, how do I set focus on first field and then, after barcode input, automatically focus this set
In C#, how do I set focus on first field (which is limited to 8 characters read by bar code) and then, after barcode input is done, automatically focus this set to field 2? Thanks your help.
You can't make it quite automatic, but if you can catch the event when barcode data is available, you set the control to have focus in your code using the ActiveControl property of the Form class:



Download: The Developer's Guide to IoT
The IoT world may be exciting, but there are serious technical challenges that need to be addressed, especially by developers. In this handbook, learn how to meet the security, analytics, and testing requirements for IoT applications.
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
You also agree that your personal information may be transferred and processed in the United States, and that you have read and agree to the Terms of Use and the Privacy Policy.
class BarcodeForm : Form { ... void barCode1_DataAvailable(object sender, EventArgs e) { // Check that active control is a TextBox TextBox textBox = this.ActiveControl as TextBox; if( textBox == null ) return; // Get data from the barcode reader textBox.Text = GetBarcodeData(); // Set the next active control if( textBox == textBox1 ) this.ActiveControl = textBox2; } }
The ActiveControl property is the control that currently has focus, and changing it changes the control with focus.
Dig Deeper on Win Development Resources
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.
Meet all of our Microsoft .Net Development experts
Start the conversation
0 comments