Search code examples
c#winformsbarcode-scanner

How to add the value of barcode scanner in textbox


I have multiple textboxes in my WindowsForm. Whenever I scan with Barcode Scanner, I should click the textbox first, then scan. However, I want the barcode scanner's value to be placed on a specific textbox whenever I scan. Is there a specific code or option for that?


Solution

  • So the scanner working properly and it gives you the values to the selected textbox. By clicking on textbox control, you are giving the focus to that control. so do it programmatically while loading the form using textBox1.Focus(); method; Let Form1 be your form and textBox1 be the respective textbox, the The code would be like the following:

    public partial class Form1 : Form
    {
        private void Form1_Load(object sender, System.EventArgs e)
        {
            textBox1.Focus();
        }
    }