Barcode scanning stops showing Messagebox

2019-09-08 06:39发布

问题:

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.