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 文本框掩码
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 将数据集转换为列表 2022-01-01
- 如果条件可以为空 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
