Win Forms 文本框掩码 [英] Win Forms text box masks

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

问题描述

如何将掩码放在 win 表单文本框上,以便它只允许数字?以及它如何用于其他掩码数据、手机 zip 等.

How can I put mask on win form text box so that it allows only numbers? And how it works for another masks data, phone zip etc.

我正在使用 Visual Studio 2008 C#

I am using Visual Studio 2008 C#

谢谢.

推荐答案

您想阻止不允许的输入还是在可以继续之前验证输入?

Do you want to prevent input that isn't allowed or validate the input before it is possible to proceed?

前者可能会使用户在按键时感到困惑,但没有任何反应.通常最好显示他们的按键但显示输入当前无效的警告.例如,设置屏蔽电子邮件地址正则表达式可能也相当复杂.

The former could confuse users when they press keys but nothing happens. It is usually better to show their keypresses but display a warning that the input is currently invalid. It's probably also quite complicated to set up for masking an email-address regular expression for example.

查看 ErrorProvider 以允许用户键入他们想要的内容,但在键入时显示警告.

Look at ErrorProvider to allow the user to type what they want but show warnings as they type.

对于仅允许数字的文本框的第一个建议,您可能还需要考虑 NumericUpDown.

For your first suggestion of a text box that only allows numbers, you might also want to consider a NumericUpDown.

这篇关于Win Forms 文本框掩码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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