Search code examples
c#rfid

make cursor just focuses on textbox in c#


I have a textbox in my c# application that gets the code from RFID Reader The RFID reader is connected to my computer using USB port .So My textbox should always be aware to read the data from RFIDReader because i can't lose the data .

The RFID Reader is plug and play .and it works like a keyboard and reads the data from the RFID card and returns the serial .

My solution is just create a textbox to get the received data .But how can i sure that every time the cursor is focused on my textbox to get the data .Do you have better solution if No My question is :

how can i sure that every time the cursor is focused on my textbox to get the data?

maybe the better solution is get the data from the socket ?!


Solution

  • To make your textbox always the focused control, set the focus back when it's lost:

    textBox1.Leave += (o, e) => { textBox1.Focus(); };
    

    You should write this code into the constructor after InitializeComponent.