Reputation: 5876
I have to read values from a barcode reader with usb. I tried several things and I understood that it behave like a key strokes from keyboard. It reads the barcode and gives the value to wherever the focus is.
I was planning to fire the event to get string's lentgh of the textbox where barcode value is put, but if the barcode value is 20 chars, the event will fire 20 times to get the string's length. And users might use different types of barcode formats as well. So I cannot be sure about the length
what is the best way to read from barcode scanner in C#?
Upvotes: 0
Views: 1629
Reputation: 48696
Most bar code scanners have a termination code that you can set it up to use. Some also have an initialization code. If your scanner has these, you just set up the initialization code and the termination code and just use those as delimiters. At the very least, it will have a termination code. Usually you can set it to or .
Upvotes: 1
Reputation: 984
First it is helpful to put a suffix and maybe a prefix in your scanner which is appended to every barcode-scan. After that you should set "keypreview" in every form to true. With that option you are able to "catch" the barcode with the eventhandling. After this you can split your barcode and put him in the field you want or to do some filter in the grid or other special operations. Hope this helps.
Upvotes: 2