MaskedTextProvider Question

  • Thread starter Thread starter Mark Collard
  • Start date Start date
M

Mark Collard

I need to display a MaskedTextBox that has 2 different prompt characters. Is
this possible (maybe using the MaskedTextProvider)? If so, can you please
show me an example on how to do it.

Many thanks
 
Hi Mark,

If by two prompt characters you mean like __/__ for a date input, this can
be done by setting the mask to display / and use _ as prompt character

maskedTextBox1.Mask = "##\\/##";
maskedTextBox1.PromptChar = '_';
 
No. I mean 2 different prompt characters.

A # character to prompt the 0 mask character and a _ to prompt the 9 mask
character.

So if the mask was 009900, you would see ##__## in the Masked Text box.



Morten Wennevik said:
Hi Mark,

If by two prompt characters you mean like __/__ for a date input, this can
be done by setting the mask to display / and use _ as prompt character

maskedTextBox1.Mask = "##\\/##";
maskedTextBox1.PromptChar = '_';


--
Happy Coding!
Morten Wennevik [C# MVP]


Mark Collard said:
I need to display a MaskedTextBox that has 2 different prompt characters. Is
this possible (maybe using the MaskedTextProvider)? If so, can you please
show me an example on how to do it.

Many thanks
 
Hi Mark,

I don't think that is possible. The ability to add your own
MaskedTextProvider to a MaskedTextBox appears to only apply to custom
configured standard MaskedTextProviders, inheriting MaskedTextProvider does
not expose any usefull overridable properties or methods.

Overriding ToString() or Text property in an inherited TextBox does not
appear to work either. A TextBox is system rendered for speed and the
overrideable OnPaint events does not do anything.

You may be able to force this behaviour using a regular or inherited TextBox
with its text set to "##__##" and handle the KeyDown/KeyPress/TextChanged
events to attempt to replace characters instead of adding them.

--
Happy Coding!
Morten Wennevik [C# MVP]


Mark Collard said:
No. I mean 2 different prompt characters.

A # character to prompt the 0 mask character and a _ to prompt the 9 mask
character.

So if the mask was 009900, you would see ##__## in the Masked Text box.



Morten Wennevik said:
Hi Mark,

If by two prompt characters you mean like __/__ for a date input, this can
be done by setting the mask to display / and use _ as prompt character

maskedTextBox1.Mask = "##\\/##";
maskedTextBox1.PromptChar = '_';


--
Happy Coding!
Morten Wennevik [C# MVP]


Mark Collard said:
I need to display a MaskedTextBox that has 2 different prompt characters. Is
this possible (maybe using the MaskedTextProvider)? If so, can you please
show me an example on how to do it.

Many thanks
 
Back
Top