Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding the PromptChar for .NET's MaskedTextBox

Is there a way to use MaskedTextBox without displaying the PromptChar? I would like to specify a mask to validate input against, but I don't want any prompt characters to take up space during edit mode.

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

Setting PromptChar to (" ") doesn't work. Setting it to Zero-width space (\u200B) seems to work, but weird things happen when the mask reaches a certain length (13 characters seems to be the magic number). Or would it be best to just roll my own?

like image 754
Jeremy Avatar asked Dec 13 '22 02:12

Jeremy


1 Answers

This is an old question, but hopefully this will help others stumbling upon the same issue. For me on .net 2.0 and above there is the property, 'HidePrompt', setting this to true hides the prompt text, until you click on the field. So, first set your prompt character to a space " ", and then change the 'InsertKeyMode' to "Insert", and then set the 'HidePrompt' to True. Changing the prompt character to a space prevents the prompt from being seen when the user clicks on it, hideprompt hides it in general, and insert mode takes the user to the beginning of the field instead of allowing them to click in the middle of the prompt character field.

like image 71
Jarrod Christman Avatar answered Dec 16 '22 18:12

Jarrod Christman