Win Forms text box masks(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 文本框掩码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Win Forms 文本框掩码


- 为什么 C# 中的堆栈大小正好是 1 MB? 2022-01-01
- 使用 rss + c# 2022-01-01
- 是否可以在 .Net 3.5 中进行通用控件? 2022-01-01
- 在 LINQ to SQL 中使用 contains() 2022-01-01
- C# 通过连接字符串检索正确的 DbConnection 对象 2022-01-01
- Azure Active Directory 与 MVC,客户端和资源标识同一 2022-01-01
- Windows 喜欢在 LINUX 中使用 MONO 进行服务开发? 2022-01-01
- CanBeNull和ReSharper-将其用于异步任务? 2022-01-01
- 在 C# 中异步处理项目队列 2022-01-01
- 带问号的 nvarchar 列结果 2022-01-01