Winforms禁用文本框上的键盘输入,但保持文本框处于启用状态 [英] Winforms disabling keyboard input on textbox but keeping textbox enabled

查看:111
本文介绍了Winforms禁用文本框上的键盘输入,但保持文本框处于启用状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这种情况就是这样;

我需要禁用文本框才能通过键盘从用户 接受输入。但是文本框应该使用诸如条形码阅读器之类的设备进行输入。我想握住一个计时器,并计算两个按键之间的时间间隔(尚不清楚)。但是也许有一种属性或更聪明的算法呢?

I need to disable textbox to take input from user by keyboard. But textbox should take inputs using kind of devices like barcode reader. I thought to hold a timer and take the timespan between two key strokes (not clear yet). But maybe there is a property or smarter algorithm for that ?

p.s。它是Windows窗体应用程序。

p.s. it is a windows forms application.

推荐答案

您说过,您需要支持任何条形码读取器,通常都可以模拟键盘,因此,可能不存在一种以编程方式区分键盘输入和条形码读取器输入的简便方法。

You said you'll need to support any barcode reader, which usually emulate a keyboard, therefore there probably isn't an easy way to programmatically distinguish between input from a keyboard and a barcode reader.

您关于使用计时的想法是一个好主意,尽管我d有所不同。我将 Timer 添加到 Form 并在将第一个字符输入<$ c $时启动它c> TextBox 。计时器应设置为非常短的时间范围,并应禁用自动重启功能。计时器关闭后,检查 TextBox 是否具有有效的条形码,如果有效,则进行处理。无论哪种方式,都先清除文本框。

Your idea about using timing is a good one, although I'd do something slightly differently. I'd add a Timer to the Form and start it when the first character is entered into the TextBox. The timer should be set to a very short time span and should have auto-restart disabled. When the timer goes off, check if the TextBox has a valid barcode, and if does, process it. Either way, clear the text box afterwards.

然后,任何试图使用键盘的人都会看到他们键入的文本会消失,而条形码扫描仪(键入'非常快)仍然可以使用。

It would then appear to anyone attempting to use the keyboard that their typed text simply disappears, while a barcode scanner (which 'types' very fast) would still work.

这篇关于Winforms禁用文本框上的键盘输入,但保持文本框处于启用状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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