带有WPF应用程序的条形码扫描仪

带有WPF应用程序的条形码扫描仪

本文介绍了带有WPF应用程序的条形码扫描仪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的计算机上连接了条形码扫描仪(蓝牙),用于扫描某些条形码.扫描仪的行为就像键盘一样,并返回其扫描的内容.在我的WPF应用程序中,我有一些文本框供用户手动输入产品编号,修订版本号,箱号和批号.

I have a barcode scanner (bluetooth) connected to my computer to use for scanning some barcodes. The scanner acts exactly like a keyboard does and returns whatever it scans. In my WPF application I have some textboxes for the user to manually enter in a product number, revision number, bin number, and lot number.

我希望用户能够扫描QR/Bar吗?随时包含所有这些信息的代码.所以我有几个问题:

I would like the user to be able to instead scan the QR/Bar? code which has all that information in it at any time. So I have a few issues:

  1. 是否可以将条形码聚焦在应用程序中的任何内容上而不会像键盘那样将其写出来?例如,我现在突出显示了一个随机文本框,但是我去扫描代码-我不希望代码填充该随机文本框-我希望将所有扫描的文本都放入变量中.

  1. Is it possible to scan a barcode with your focus on anything in the app and NOT write it out like a keyboard? Example, I have a random textbox highlighted right now but I go and scan a code - I dont want the code to fill in this random textbox - I would want something like all the scanned text goes into a variable.

如果无法执行步骤1.我目前设置的方式是您需要单击一个特定的文本框.在TextChanged上哪个会解析它,并尝试找出需要去的部分.但是,当将每个字符添加到框中时,它将触发.每个代码约有30个字符,因此这将极大地减慢它的速度.我试图查看还有哪些其他事件可能有效,但没有看到该问题的任何其他解决方案?还有其他我想念的事情吗?

If step 1 is not possible. The way I currently have it set up is you need to click into a specific textbox. Which on TextChanged will parse it and try to figure out where the pieces need to go. But it will trigger when each character is added to the box. I have about ~30 characters per code so this will slow it down tremendously. I tried to see what other event might work but I don't see any other solution to that issue? Is there some other event that I'm just missing?

谢谢

推荐答案

private string barCode = string.Empty; //TO DO use a StringBuilder instead
private void Window_Loaded(System.Object sender, System.Windows.RoutedEventArgs e)
{
    MainWindow.PreviewKeyDown += labelBarCode_PreviewKeyDown;
}

private void labelBarCode_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if ((44 == e.Key)) e.Handled = true;
    barCode += e.Key;
    //look for a terminator char (different barcode scanners output different
    //control characters like tab and line feeds), a barcode char length and other criteria
    //like human typing speed &/or a lookup to confirm the scanned input is a barcode, eg.
    if (barCode.Length == 7) {
       var foundItem = DoLookUp(barCode);
       barCode = string.Empty;
    }
}


查看更新,截至2019年3月: https://stackoverflow.com/a/55411255/495455

这篇关于带有WPF应用程序的条形码扫描仪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 00:37