4

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

BudBrot
  • 1,341
  • 2
  • 24
  • 44
  • 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 - http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.multiline(v=vs.110).aspx - – Schuere Nov 22 '13 at 08:55
  • "not fully supported"... well, ok. I would say its not working and should be hided but ok. Thanks you. – BudBrot Nov 22 '13 at 09:00
  • 1
    to bad it isn't a real solution :s – Schuere Nov 22 '13 at 09:03
  • 1
    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 Nov 22 '13 at 09:10

1 Answers1

2

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

Pawel Cioch
  • 2,895
  • 1
  • 30
  • 29
  • If new line is part of one value then maybe you need to use one MaskedTextBox and re-code it to use some Regex etc, or maybe use just TextBox and code total custom validation – Pawel Cioch Jan 03 '14 at 23:14
  • "using textbox and code custom validation" - Thats the way i did it. I mainly was supprised that Microsoft doesnt remove or at least hide useless propertys like *Multiline* :) I mark this as answer cause it works. – BudBrot Jan 08 '14 at 07:34
  • I'm glad I was able to help. Thanks! – Pawel Cioch Jan 09 '14 at 23:34