当程序没有焦点时读取条形码?
我有一个表单,可以从条形码阅读器将数据读取到文本框。 并且有一些像这样的编码条形码
W12346S1 is first step of a work
W12346S2 is second step of a work
W12346S3 is third step of a work
...
U123 is a user he read his code to make process
M456 is a machine user do the work on this machine.
,所以我想将数据从 form_KeyDown() 事件或不同事件中的第一个字符(W,U,M)写入真实文本框。
( 真正的文本框意味着如果用户读取以 W 键开头的条形码,则让程序将条形码数据写入“work tekxtbox”,或者如果他读取以 U 开头的条形码,程序会将条形码数据写入用户文本框等...
) 我想让代码选择自己的文本框。有什么办法呢?
注意:如果我使用 textbox1.Text += e.KeyData.ToString();
输出为:ShiftKey、ShiftW、ShiftD1D2D3D4D6ShiftKey、ShiftS、ShiftD2 W12346S2 适用于 W12346S2
I have a form which I read data to textbox from a barcode reader.
and there are some codded barcodes like this
W12346S1 is first step of a work
W12346S2 is second step of a work
W12346S3 is third step of a work
...
U123 is a user he read his code to make process
M456 is a machine user do the work on this machine.
so I want to write data to true textboxes from firs char (W, U, M) in form_KeyDown() event or one different.
(
true textboxes mean if user read a barcode which start with W key let the program write the barcode data to "work tekxtbox" or if he read abarcode which start with U program will write the barcode data to user textbox etc...
)
I wanna make this let the codes select its own textboxes. what is the way?
note: if I use textbox1.Text += e.KeyData.ToString();
the output is : ShiftKey, ShiftW, ShiftD1D2D3D4D6ShiftKey, ShiftS, ShiftD2 W12346S2
for W12346S2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
难道你不能只阅读文本并得到如下内容:
Can't you just read in the text and have something like this:
条形码阅读器的输入可以与键入的按键区分开来吗?如果是这样,我建议输入的条形码不要由击键处理程序处理,而是使用它们自己的特殊处理程序,该处理程序将等到它扫描整个条形码,然后将其粘贴到适当的框中。
如果读者的输入看起来像击键,那么事情可能会更加棘手。您可能想要拦截进入表单的所有击键,查看每个击键,确定它是否看起来可能是条形码的一部分,如果是,则对其进行缓冲。每当您确定缓冲的数据不是条形码的一部分(由于后续字符或计时器到期)时,请触发您自己的击键事件以重新发出击键。确保按顺序处理所有击键可能有点棘手,但希望不会太糟糕。防止条形码阅读器的击键进入不适当的字段可能比在进入不适当的字段后提供良好的用户体验更容易。
Can input from your barcode reader be distinguished from typed keystrokes? If so, I would recommend that incoming barcodes not be handled by the keystroke handler, but instead use their own special handler which will wait until it has scanned an entire barcodes and then stick it in an appropriate box.
If the input from your reader looks like keystrokes, things are apt to be a little more tricky. You may want to intercept all keystrokes going to your form, look at each keystroke, determine whether it looks like it might be part of a barcode, and buffer it if so. Any time you determine that the buffered data isn't part of a barcode, either because of following characters or because a timer expires, fire your own keystroke events to re-issue the keystrokes. Ensuring that all keystrokes are handled in order may be a little tricky, but hopefully not too bad. It will probably be easier to prevent keystrokes from the barcode reader from going into an inappropriate field, than to provide a good user experience after they do.