70-526 MCTSMaskedTextBox controlThe The Inheritance hierarchySystem.Object
System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.Control
System.Windows.Forms.TextBoxBase
System.Windows.Forms.MaskedTextBox
Useful propertiesAllowPromptAsInput - Indicates whether PromptChar can be entered as valid data by the user.
AsciiOnly - Indicates whether the MaskedTextBox control accepts characters outside of the ASCII character set.
BeepOnError - Indicates whether the masked text box control raises the system beep for each user key stroke that it rejects.
CutCopyMaskFormat - Determines whether literals and prompt characters are copied to the clipboard.
HidePromptOnLeave - Indicates whether the prompt characters in the input mask are hidden when the masked text box loses focus.
InsertKeyMode - Specifies the text insertion mode of the MaskedTextBox control.
Mask - Specifies the input mask to use at run time.
PromptChar - Specifies the character used to represent the absence of user input in MaskedTextBox.
RejectInputOnFirstFailure - Indicates whether the parsing of user input should stop after the first invalid character is reached.
ResetOnPrompt - Determines how an input character that matches the prompt character should be handled.
ResetOnSpace - Determines how a space input character should be handled.
SkipLiterals - Indicates whether the user is allowed to re-enter literal values.
TextMaskFormat - Determines whether literals and prompt characters are included in the formatted string.
The Mask propertyThis property allows you to define a string that represents the required format that the string must be input into the MaskedTextBox. The default value is an empty string which allows any input. The Mask is composed of one or more of the masking elements from the table below. The MaskedTextProvider associated with the MaskedTextBox provides the parsing engine for the Mask.
The decimal (.), thousandths (,), time (:), date (/), and currency ($) symbols display those symbols as defined by the culture of the application. These can be forced to another through the use of the FormatProvider property. Characters are inserted into the mask at run time are controlled by the InsertKeyMode property. Navigation through the mask is done through the left and right arrow keys or the mouse cursor, and optional positions in the mask can be skipped by entering a space. Example Mask StringsSome example of mask strings are shown below: (99999)-0000000 could be used for a UK telephone number. The area code is optional, so the user can either enter spaces within the brackets, or place the mouse pointer directly at the start of the mask represented by the first 0. If the user entered 01805123456, then the displayed text would be (01805)-123456. 00/00/0000 could be used to represent a date (day, numeric month, year) in international date format. The "/" character is a logical date separator, and will appear to the user as the date separator appropriate to the application's current culture. Is the user entered 01041971, then the displayed text would be 01/04/1971 dependant upon the application's current culture. 00->L<LL-0000 could also be used to represent a date (day, month abbreviation, and year) in which the three-letter month abbreviation is displayed with an initial uppercase letter followed by two lowercase letters. If the user entered 01apr1971, then the displayed text would be 01-Apr-1971. $999,999.00 can be used to represent a currency value in the range of 0 to 999999. The currency, thousandth, and decimal characters will be replaced at run time with their culture-specific equivalents. If a user entered 12345678, then the displayed text would be £123,456.78 in the UK. Setting masked text graphicallyClicking the smart tag icon ![]() Clicking on the Set Mask... item causes the Input Mask dialog to appear. ![]() Once you have chosen a mask from the list, entering text/numbers in the preview text box allows you to test out the mask. ![]() MSDN referencesOther
|