问题
从扫描仪读取数据时如何移除对焦按钮?
详情
我需要从条形码扫描器读取数据到窗体。
我可以毫无问题地阅读数据成功
我的问题是,如果我把按钮放在形式上,它专注于它而不是读取数据
以便在阅读数据时如何添加按钮以形成并移除焦点
这实际上是我需要解决的问题。
public partial class Form1 : Form
{
DateTime _lastKeystroke = new DateTime(0);
List<char> _barcode = new List<char>(10);
public Form1()
{
InitializeComponent();
}
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
TimeSpan elapsed = (DateTime.Now - _lastKeystroke);
if (elapsed.TotalMilliseconds > 100)
_barcode.Clear();
// record keystroke & timestamp
_barcode.Add(e.KeyChar);
_lastKeystroke = DateTime.Now;
// process barcode
if (e.KeyChar == 13 && _barcode.Count > 0)
{
string msg = new String(_barcode.ToArray());
_barcode.Clear();
}
}
}
}