Hide PromptChar for .NET MaskedTextBox

Is there a way to use MaskedTextBox without displaying PromptChar? I would like to specify a mask for checking input, but I do not want any prompt characters to take up space during edit mode.

The reason for this is that when I want to accept free text with a limited set of characters, all characters are optional alphanumeric characters. The problem is that when I select all the text, even the invitation characters are selected.

Setting PromptChar to ("") does not work. Installing it in a zero-width space (\ u200B) seems to work, but strange things happen when the mask reaches a certain length (13 characters seem to be a magic number). Or would it be best to just collapse mine?

+4
source share
3 answers

This is an old question, but hopefully it helps others stumble upon the same problem. For me, on .net 2.0 and higher there is the β€œHidePrompt” property, setting this to true hides the invitation text until you click on the field. So first set the space character ", and then change" InsertKeyMode "to" Insert "and then set HidePrompt to True. Changing the space character prevents the screen from showing when the user clicks on it, hideprompt hides it altogether, and the insert mode returns the user to the beginning of the field, and does not allow them to click in the middle of the tooltip character field.

+11
source

How easy it is to use a text box and then use a regular expression (or some other validation process) to make sure the text is valid when the control loses focus. Alternatively, if it is a Window application, go to the TextChanging (or KeyPress) event and stop all invalid characters that actually get in the input.

This can also be done in javascript for the web page.

+1
source

Have you checked the CutCopyMaskFormat property?

it seems to be set to: IncludePrompt or IncludePromptAndLiterals .

0
source

All Articles