How to set focus on textbox 4 only to read barcode ?

Posted by Ahmedsa under C# on 2/20/2017 | Points: 10 | Views : 380 | Status : [Member] | Replies : 1
I work with c# windows form vs 2015
i create windows form have 4 textboxes
textbox1,2,3,4 to read data by barcode reader using usb and work as keyboard
I read data from bar code scanner and receive reading in text box 4
but some times it read in textbox2 or textbox3 because cursor mouse moved
so that how to set focus on textbox 4 to read data from scanner ?
my code as below

 private void textBox4_KeyDown(object sender, KeyEventArgs e)
{

string[] lines = textBox4.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

if (lines.Length > 4)
{
textBox1.Text = lines[1].Substring(lines[1].IndexOf(":") + 1);
textBox2.Text = lines[2].Substring(lines[2].IndexOf(":") + 1);
textBox3.Text = lines[3].Substring(lines[3].IndexOf(":") + 1);
textBox5.Text = lines[4].Substring(lines[4].IndexOf(":") + 1);
}





Responses

Posted by: A2H on: 2/20/2017 [Member] [MVP] Silver | Points: 25

Up
0
Down
Try setting the focus to textbox4 on formload event like below

public partial class Form1 : Form
{
public Form1()
{
this.ActiveControl = textBox4;
}
}


Thanks,
A2H
My Blog

Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response