扫描条形码时产生事件 [英] Spawn an Event when a Barcode is Scanned

查看:119
本文介绍了扫描条形码时产生事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用C#制作清单应用程序.该应用程序需要由条形码扫描仪驱动,即.每当扫描条形码时,我都需要它产生一个事件,以便它可以采取必要的措施.我尝试在文本框中使用TextChanged事件,但是它为字符串中的每个字符而不是整个字符串产生一个事件.我正在使用USB条形码扫描仪.我们将不胜感激.

Hi,

I am making an inventory application using c#. The application needs to be driven by the Barcode Scanner ie. whenever a barcode is scanned, i need it to spawn an event so that it can take the necessary action. I have tried using a TextChanged event in a textbox, but it spawns an event for each character in the string rather than one for the whole string. I am using a USB Barcode Scanner. Any help would be appreciated.

推荐答案

您是否看到是否有指示扫描完成时间的事件?那可能在条形码读取器的驱动程序或接口对象中.如果有,您可以等待该事件被触发,然后*然后*在文本框中检查数据.或者,扫描仪可能会发送一个特殊字符来表明已完成.很难说这是因为您是扫描仪的专家.
Did you see if there is an event that indicates when the scan is complete? That would probably be in the barcode reader''s driver or interface object. If there is, you can wait for that event to be fired, and *then* check the textbox for data. Or maybe the scanner sends a special character to indicate that it''s done. It''s kinda hard to say because you''re the guy with the scanner.


另一个说明,请考虑文本框是否是唯一可以处理来自扫描仪输入的UI元素.条码读取器.根据情况,无论哪个对象都具有焦点,处理条形码都是合理的.如果需要,您可以在窗体/窗口/等级别正确连接按键(或类似事件).
Another note, consider if the text box is the only UI element that can handle the input from the barcode reader. Depending on the situation it may be reasonable to handle the barcode no matter what object has the focus. If this is needed, you could wire the keypress (or similar) event correctly at form/window/etc level.


对于我开发的库应用程序,我也有同样的情况.我让扫描仪添加了< enter>关键代码到扫描代码的末尾.这样,我将只在文本框中处理此事件,这将使用户可以使用扫描仪或在框中键入值,然后按< enter>无需更改代码.当然,在这种情况下,文本框必须具有焦点.
I had the same situation for a library app I developed. I had the scanner add the <enter> key code to the end of the scanned code. That way, I would handle just this event in the textbox and this would let the user either use the scanner or type the value in the box and press <enter> without altering the code. Of course, the textbox had to have the focus in this case.


这篇关于扫描条形码时产生事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆