Barcode scanning stops showing Messagebox

ぐ巨炮叔叔 提交于 2019-12-25 08:19:22

问题


I am working on a desktop application in c# with a barcode scanning module. The problem is that whenever I scan a barcode the application stops showing Messageboxes. Application does ot throw any exception, it just executes the code.

Application works perfectly before scanning a barcode.

I have no idea why is this happening and how do I solve it.

This is my code:

if (string.IsNullOrEmpty(BarcodeScan) && e.KeyChar.ToString() == "*")
   BarcodeScan = e.KeyChar.ToString();

else if (Regex.IsMatch(BarcodeScan + e.KeyChar.ToString(), @"^[*]\d+$"))
   BarcodeScan += e.KeyChar.ToString();

else if (Regex.IsMatch(BarcodeScan + e.KeyChar.ToString(), @"^[*]\d+[*]$"))
{
   BarcodeScan += e.KeyChar.ToString();
   ArticalID = BarcodeScan.Substring(1, BarcodeScan.Length - 2);

   //Code to find article in DB

   ArticalID = string.Empty;
   BarcodeScan = string.Empty;
}
else
{
   if (BarcodeScan.StartsWith("*"))
   {
        BarcodeScan = string.Empty;
   }
}

回答1:


As far as I understand your question: a barcode scanner sends the scanned numbers / characters mostly with an "Enter" at the end. Maybe that enter closes your MessageBox by invoking the default button.



来源:https://stackoverflow.com/questions/8604130/barcode-scanning-stops-showing-messagebox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!