Win Forms 文本框掩码

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

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)