与条形码扫描仪读数值到文本框的问题 [英] problem with barcode scanner reading value into text box
问题描述
我有一个条形码扫描仪读出此活动文本框条形码和显示该字符串。
我遇到的问题是,我需要一个条形码尽快作为其扫描(无用户确定按钮)。
I have a barcode scanner which reads the string of the barcode and displays in the active text box. The issue I am having, is that I need that barcode to be used as soon as its scanned (no user "ok" button).
当我做文字更改事件,它一旦条形码的第一个字符输入到文本框中闪光。 (即如果条形码是123r54122,它激发'1'的文本框)。
When I do the Text Changed event, it fires as soon as the first character of the barcode is entered into the text box. (i.e if the barcode is 123r54122, it fires with '1' in the text box).
有没有一致的结束符条形码或标准长度。所以,我怎么会去当整个字符串已被阅读射击的方法?
There is no consistent end character to the barcode, or standard length. So how would I go about firing a method when the WHOLE string has been read in?
推荐答案
您可以验证文本长度(我认为这是条形码不变)。
例如。订阅TextChange事件,如果文本长度= barCodeLength然后抬起扫描事件
You can verify text length (I think it is constant for bar codes). E.g. subscribe to TextChange event and if text length = barCodeLength then raise Scanned event.
如果条形码具有可变长度的你可以尝试这样的事:
1)定义
If bar code has variable length you can try something like this: 1) define
private Timer _timer;
private DateTime _lastBarCodeCharReadTime;
2)初始化定时器
2) initialize timer
_timer = new Timer();
_timer.Interval = 1000;
_timer.Tick += new EventHandler(Timer_Tick);
3)添加处理程序
3) add handler
private void Timer_Tick(object sender, EventArgs e)
{
const int timeout = 1500;
if ((DateTime.Now - _lastBarCodeCharReadTime).Milliseconds < timeout)
return;
_timer.Stop();
// raise Changed event with barcode = textBox1.Text
}
Changed事件
4 )在TextChanged事件处理程序中添加此
4) in TextChanged event handler add this
private void textBox1_TextChanged(object sender, EventArgs e)
{
_lastBarCodeCharReadTime = DateTime.Now;
if (!_timer.Enabled)
_timer.Start();
}
这篇关于与条形码扫描仪读数值到文本框的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!