Behavior Settings in Windows Forms MaskedTextBox (MaskedEditBox)

The behavior settings of the MaskedEditBox control are discussed below.

Prompt and padding character settings

The MaskedEditBox control allows you to add prompt characters in the input.

MaskedEditBox Properties Description
AllowPrompt Specifies if the prompt character can be allowed to be entered as an input character.
PaddingCharacter Specifies the character that will be used instead of mask characters when the mask position has not been filled when the text property is used.
PaddingCharacterInt Gets / sets the integer version of the padding character.
Prompt Character Gets / sets the character that will be used instead of the mask characters when the mask position has not been filled.
PromptCharacterInt Gets / sets the integer version of the PromptCharacter.
PassivePromptCharacter Gets / sets the character that will be used instead of the mask characters when the mask position has not been filled (when the control does not have the focus).
PassivePromptCharacterInt Gets / sets the integer version of the PassivePromptCharacter.
this.maskedEditBox1.AllowPrompt = true;
this.maskedEditBox.PaddingCharacterInt = 0;
this.maskedEditBox1.PromptCharacterInt = 37;
this.maskedEditBox1.PassivePromptCharacterInt = 47;
Me.maskedEditBox1.AllowPrompt = True
Me.maskedEditBox.PaddingCharacterInt = 0
Me.maskedEditBox1.PromptCharacterInt = 37
Me.maskedEditBox1.PassivePromptCharacterInt = 47

NOTE

 We can trim the additional spaces present in the mask by setting the PaddingCharacterInt property to ‘0’.

MaxLength

The maximum length of the text can be set using the property given below.

MaskedEditBox Property Description
MaxLength Specifies the maximum number of characters that can be entered into the edit control. The default value is set to '32767'.
this.maskedEditBox1.MaxLength = 32800;               
Me.maskedEditBox1.MaxLength = 32800

ReadOnly

The ReadOnly mode can be enabled for the MaskedEditBox control using the below given property.

MaskedEditBox Property Description
ReadOnly Specifies whether the text in the edit control can be changed or not.
this.maskedEditBox1.ReadOnly = true;
Me.maskedEditBox1.ReadOnly = True