WinForms MaskedTextBox接受某些字符 [英] WinForms MaskedTextBox to accept certain chars

查看:84
本文介绍了WinForms MaskedTextBox接受某些字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MaskedTextBox,它可以接受字母数字字符,但我也想接受方括号()".我该如何更改遮罩以接受方括号?

I have a MaskedTextBox that accepts alpha numeric chars but I also want to accept brackets "()". How can I change the mask to accepts brackets also?

推荐答案

请参见以下类似问题的答案:

See this answer to a similar question:

如何在C#中将Regex表达式设置为MaskedTextBox的掩码?

您可能应该只使用正则验证,而不是使用掩码,然后才可以直接使用正则表达式.确保(常规(未屏蔽)文本框)的CausesValidation属性为true,然后截取Validating事件,如果正则表达式不匹配,则将CancelEventArgs.Cancel设置为true.

Instead of using a mask, you should probably just use regular validation, and then you can use the regular expressions directly. Make sure that the CausesValidation property of the (regular, not masked) textbox is true, then intercept the Validating event and if the regular expression doesn't match, set the CancelEventArgs.Cancel to true.

这篇关于WinForms MaskedTextBox接受某些字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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