4
votes

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
From the msdn documentation: Gets or sets a value indicating whether this is a multiline text box control. This property is not fully supported by MaskedTextBox. I suggest you make a usercontrol representing 4 maskedtextboxes and voila, you're set - msdn.microsoft.com/en-us/library/… - - Schuere
"not fully supported"... well, ok. I would say its not working and should be hided but ok. Thanks you. - BudBrot
to bad it isn't a real solution :s - Schuere
Bear in mind that the purpose of this control (accepting characters under very specific conditions) seems to be against what multiline implies. For example: in your code you want a mask allowing just numbers and "/"; how should the multiline characters be understood? Always accepted for every mask? And what if you want to design a mask only accepting new line characters (or anything but new line characters)? Or see it in another way: how many password inputboxes which accept new lines have you ever seen? It seems that you will have to create your own control. - varocarbas

1 Answers

2
votes

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