WPF:特定输入文本框(用于电话号码等) [英] WPF: Specific input textboxes (for phone numbers and such)
问题描述
我不知道这叫什么,但我确定这有一个名字,并且已经多次完成.
I don't know what this is called, but I'm sure theres a name for this and it has been done multiple times.
我有一些理想情况下只允许特定输入的文本框,例如电话号码、银行帐号和类似内容的框.
例如,电话号码输入应采用以下格式:000-000-0000 但我也希望它接受没有区号的号码,例如:000-0000
I have some textboxes that ideally would only allow specific input, like a box for phone number, bank account numbers and stuff like that.
For instance, a phone number input should be in the following format: 000-000-0000 but I'd also like it to accept a number without an area code like : 000-0000
现在我制作了一个从文本框派生的控件,它只接受数字输入,但我不知道如何让破折号出现在正确的位置,而无需在 TextChanged 事件中进行一些粗暴的修改.
Now I have made a control derived from textbox that accepts only numeric input, but I have no idea how I would get the dashes to appear in the right spots without doing some fugly hacks in the TextChanged event.
我知道这可能已经死了,我试着用谷歌搜索,但我没有正确的词.
I know this has probably been done to death, I tried to google but I didn't have the right words.
推荐答案
你应该使用掩码文本框
有一些免费的开源掩码文本框
You should use mask textboxes
there is some free open source mask textboxes
看这里
这篇关于WPF:特定输入文本框(用于电话号码等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!