TextBox中的约束 [英] Constraints in TextBox

查看:79
本文介绍了TextBox中的约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

有没有一种方法可以限制用户在TextBox控件中仅输入数字?

我可以使用TextChanged事件处理程序并删除数字以外的任何字符,但是有更简单的方法吗?

非常感谢您的帮助.

谢谢,

Hello Guys,

Is there a way to restrict users to input only numbers in TextBox control?

I can use the TextChanged Event handler and remove any character other than numbers but is there an easier way to do it?

Your help is highly appreciated.

Thanks,

推荐答案

如果您使用多个数字文本框,则可以构建自己的控件 ^ ].
If you are using multiple numeric text boxes you can build your own control[^].


我前一阵子可能有用- ^ ].

它是一个数字文本框,而不是一个 Number 文本框,因为它仍将输入视为字符串,不带小数点且不带符号.
I made one a while ago that may be of use - here[^].

It is a NumericTextBox rather than a NumberTextBox as it still treats the input as a string, no decimal point and no - sign.


尝试使用NumericUpDown代替.也许它将为您完成工作.
Try using a NumericUpDown instead. Maybe it will do the job for you.


这篇关于TextBox中的约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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