Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
597 views
in Technique[技术] by (71.8m points)

winforms - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...