MaskedTextBox Mask Question

Editors for WPF Forum

Posted 15 years ago by David Mullin
Avatar
I've set the Mask property of a MaskedTextBox to be ".........", which works as expected. There is an odd visual behavior that I'd like to address (if possible). If the field is empty, and I click near the right side of the field, the caret is positioned at the end of the mask - making it look like there are 10 blank characters in the field. If I start typing, the caret then jumps to the beginning of the field, and everything behaves normally.

I tried to address this through the Mask, by providing a Mask of ".?.?.?.?.?.?.?.?.?.?" which, I thought, would say "ten optional characters". The end results, however, was a field that rejected all user input (not really what I expected, but I'm an extreme novice at RegEx).

I also tried the Mask of ".{1,10}", and this looked better (in that there only appeared to be 1 blank space at the beginning). Oddly, the Mask ".{0,10}" wouldn't let me type anything.

What am I missing?

David Mullin

[Modified at 06/11/2009 11:29 AM]

Comments (5)

Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi David,

There appears to be an bug in MaskedTextBox when using {0,x}, I will let you know when I have this fixed. I will also look at the caret placement on the initial click.

When your mask is "..........", then you are saying there must be 10 characters, no more no less. So the MaskedTextBox will show 10 prompt characters or geometeries (depending on your settings) to indicate more input is required.

What are your requirements for the mask? Is it up to 10 characters, or 10 exactly?


Actipro Software Support

Posted 15 years ago by David Mullin
Avatar
I want up to 10 characters, so the {0,x} bug fix will give me what I want. Thanks!

But, about the "........." mask - the field's behavior is still a little odd. When you click in the field, the caret is at the end, making it look like there are 10 spaces in the field. If that were the case, I would expect typing to do nothing (since the field is already full), and that I have to backspace or delete the contents. However, what really happens is that, as soon as I start typing, the caret jumps to the first position. It's just not what I'd expect...
Posted 15 years ago by David Mullin
Avatar
On a possibly related note, there may be another issue with the "{1,X}" format. If I put a Mask of ".{1,100}" on the MaskedTextBox, then the UI just hangs. If I change it to ".{1,10}", the application runs, but seems to be a little sluggish.

Here's the actual XAML that I'm using for the control:

<editors:MaskedTextBox Grid.Row="3" Grid.Column="1" Mask=".{1,100}" />
David Mullin
Posted 15 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi David,

We've fixed all three issues relating to this post. In summary they are:

1. When using a mask similar to ".{0,10}", then no input was allowed. This is now fixed, and allows 0 to 10 characters.
2. When using a mask similar to ".{0,100}", then the MaskedTextBox would hang. This was related to how we were building the DFA for the associated mask, and this is now fixed.
3. When clicking on the right side of a MaskedTextBox, the caret would be positioned at the end (after the input prompts). This is now fixed, and the caret is properly positioned at the next closest editable position to the mouse click.

Thanks for reporting these issues.


Actipro Software Support

Posted 15 years ago by David Mullin
Avatar
And thank you for being so proactive in addressing them.

I've said it before, and I'll say it again, your support rocks!
The latest build of this product (v24.1.1) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.