阻止用户输入非数字值 [英] Block user from entering Non-Numeric Value

查看:94
本文介绍了阻止用户输入非数字值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio,如何阻止用户输入非数字值到文本框控件。 就像窗口计算器一样,它不允许用户输入字符串字符。

执行计算器项目。

非常感谢,

Using Visual Studio, how do I block users from entering a non-numeric value to a textbox control.  Just like the window calculator, it does not let user to enter string character.

Doing the calculator project.

Many Thanks,

推荐答案

在TextBox的PreviewKeyDownEvent中检查在eventargs中输入的密钥。您可以使用多种方法验证输入的密钥是数字密钥还是非数字密钥。最好的方法是使用RegularExpressions。如果您发现任何问题,请告诉我。然后,如果输入的密钥是非数字的,只需执行e.cancel = true;
In the PreviewKeyDownEvent of the TextBox check for the key entered in the eventargs. You can verify if the key entered is a numeric or non-numeric key by using several ways. The best way would be to use RegularExpressions. Let me know if you find any problem with this. Then if the key entered if non-numeric simply do e.cancel=true;


这篇关于阻止用户输入非数字值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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