等到文本框完成条形码扫描器的输入? Windows应用程序 [英] Wait until textbox finish input from barcode scanner ? windows application

查看:72
本文介绍了等到文本框完成条形码扫描器的输入? Windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




在我的Windows应用程序c#中,我有一个名为txtItemID的文本框

i从条形码扫描器读取id直接到我的文本框

和我检查数据库中项目的输入值

我的问题是当扫描仪读完时如何从文本框中读取输入值?



因为我不想每次在文本框中插入值时都去数据库..



请知道吗?



我尝试过:



i尝试使用文本框更改

hi
in my windows application c# , i have a textbox named txtItemID
i read id from barcode scanner direct to my textbox
and i check the input values from items in database
my problem is how can read input value from textbox when scanner is finished read ?

because i dont want to go to database every time value insert in textbox ..

please any idea ?

What I have tried:

i try to use textbox change

private void txtItemID_TextChanged(object sender, EventArgs e)
       {
           // select from database every time character input in textbox ;

       }







这种方式没用,因为我对文本框中的每个字符输入执行查询

i只有在输入完成后才能运行查询




this way is not useful because i execute query for each character input in textbox
i want to run query only when input finished

推荐答案

几种方式:



- 如果你的条形码总是有相同的长度,请等到文本框中的文字长度合适。



- 配置您的扫描仪以发送一个特殊后缀,以便您识别代码的结尾。



- 在超时输入第一个字符时启动计时器这比扫描仪发送的单个字符之间的延迟大得多,并且每次附加另一个字符时重置计时器。然后只在计时器结束时启动数据库查询 - 也就是说,在指定的计时器间隔内文本没有更改之后。



- 不要使用文本框,但直接在较低的API级别读取条形码扫描仪的传输 - 这就是我要做的。请参阅此处:使用C#的原始输入来处理多个键盘 [ ^ ](从系统的角度来看,典型的条形码扫描仪基本上是键盘。)
Couple of ways:

- If your barcodes always have the same length, wait until the text in the textbox has the right length.

- Configure your scanner to send a special suffix which will allow you to identify the end of the code.

- Start a timer when the first char is entered with a timeout that is sufficiently larger than the delay between single chars sent by the scanner and reset the timer each time another char gets appended. Then only start your database query when the timer has elapsed - that is, after the text hasn't changed for the specified timer interval.

- Don't use a textbox at all but read the barcode scanner's transmission directly at a lower API level - which is what I would do. See here: Using Raw Input from C# to handle multiple keyboards[^] (A typical barcode scanner is basically a keyboard from the system's point of view.)


这篇关于等到文本框完成条形码扫描器的输入? Windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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