从键盘在文本框输入滤波器,C# [英] Filter input from keyboard in Textbox, C#

查看:193
本文介绍了从键盘在文本框输入滤波器,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要过滤的基础上我允许输入的类型键盘的投入文本框。例如:

I want to filter the keyboard inputs into textbox based on the type of input I allow. e.g.

0,数字仅
1的字母只有
2字母数字

0 for Digits only 1 for Alphabets only 2 for Alphanumerics

因此,如果被配置和'a'按下键盘上的字符0,它不是在文本框中所示。我该怎么做,在C#?

So if 0 is configured and a character 'a' is pressed on the keyboard, it is not shown in the textbox. How do I do that in C#?

感谢

推荐答案

您需要订阅控件的KeyPress事件(和可选的KeyDown方法),如果击键都要吃套的处理的属性设置为true。阅读 MSDN 更多(样本覆盖你的问题)。

You need to subscribe to control's KeyPress event (and optionally KeyDown method), and if key stroke must be eaten set Handled property to true. Read more in msdn (with sample that cover your problem).

这篇关于从键盘在文本框输入滤波器,C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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