从扫描仪条形码读取数据时如何移除对焦按钮 [英] How to remove focus on button when reading data from scanner barcode

查看:79
本文介绍了从扫描仪条形码读取数据时如何移除对焦按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从条形码扫描器读取数据到窗体。



i可以毫无问题地读取数据成功



我的问题是,如果我把按钮放在形式上它专注于它而不是读取数据



这样如何放置按钮并将焦点移到它上面这实际上是我的问题我需要



求解。



I need to read data from bar code scanner to windows form .

i can read data success without any problem

my problem is if i put the button in form it focus on it and not reading data

so that how to put button and remove focus on it this is actually my problem i need to

solve .

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());
                label1.Text = msg;
                //queryData(msg);
                _barcode.Clear();
            }
        }
    }
}





我尝试了什么:





What I have tried:

how to remove focus on button when reading data from scanner barcode

推荐答案

永远不会从任何事物中移除焦点。你必须把注意力集中在其他一些控件上。



由于大多数条形码扫描仪只是键盘模拟器(键盘楔形),所以它们扫描的所有内容都只是键入到任何一个控制具有当时的重点。



因此,通常,您对条形码扫描器进行编程以在条形码前面添加注意序列。必须启用表单的KeyPreview属性,以便表单代码Key事件可以在目标控件执行之前获取条形码。表单键事件处理程序监视前置字符序列。当它看到序列时,您可以将焦点移动到适当的控件,通常是文本框,而来自条形码扫描器的其余按键将最终进入该控件。
You never "remove" focus from anything. You have to give the focus to some other control.

Since most barcode scanners are just keyboard emulators (keyboard wedge), everything they scan is just "typed" into whatever control has the focus at the time.

So, typically, you program the barcode scanner to prepend an attention sequence to the barcode. Your form's KeyPreview property has to be enabled so the form code Key events can get the barcode before the destination control does. The forms key event handler watches for the prepended sequence of characters. When it sees the sequence you can move the focus to an appropriate control, usually a textbox, and the rest of the keystrokes coming from the barcode scanner will end up in that control.


只需聚焦它在文本框中用于条形码扫描仪的输入。然后在Form的AcceptButton属性上,将其设置为Button1。
Just focus it in the textbox for the barcode scanner's input. Then on the Form's AcceptButton property, set it to Button1.


textBox1.Focus();


这篇关于从扫描仪条形码读取数据时如何移除对焦按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆