开发者

WinForms MaskedTextBox to accept certain chars

开发者 https://www.devze.com 2023-03-29 20:56 出处:网络
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 questi

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:

How to set Regex Expression as the Mask for a MaskedTextBox in C#?

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.


You can simply put this line of code into form constructor:

 maskedTextBox1.Mask = "(000)000.000";
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号