Multiline mask for MaskedTextBox

可紊 提交于 2020-01-03 16:49:06

问题


I have a MaskedTextBox in my Winforms application. I need a multiline mask on it, f.e:

"999999\r\n
 999999\r\n
 999999\r\n
 00/00/0000"

I read the msdn documentation and was suprised to see that there is no "new line"or something like that.

I know that i can write my own user control to fix this issue, but a masked textbox would be an easier solution. So i have 2 Questions: Is there a way to add a new Line to a mask? If not, why does the Control supports multiline - isnt that useless?

Thanks in advance


回答1:


For that I would create a custom control that would combine set of MaskedTextBox for each line Now, depending on the need, either "dumb" control with constant amount of MaskedTextBox one under another and corresponding properties for format strings

public string Format1 {get;set;} 
public string Format2 {get;set;} 
public string FormatX {get;set;} 

Or create a "smart" version, with property "LinesCount" etc, when you set to 5 it would add 5 MaskedTextBox with set anchor to left and right (for the whole control to be stretchable)

And then property

public List<string> Formats {get;set;}

each line would correspond to each MaskedTextBox

Also property values

public List<X> Values 

each line would correspond to each MaskedTextBox.Value, where X is type I don't remember it returns.

The more complicated and smart and useful control you want the more coding you need to put :) but doable



来源:https://stackoverflow.com/questions/20140622/multiline-mask-for-maskedtextbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!