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 文本框掩码
基础教程推荐
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
