MaskedEdit Control

What is it?

This class provides an easy-to-use edit control that allow you to specify the format with which all entries will be made.  Without exception.

Features

The Masked Edit control provides restricted data input as well as formatted data output. This control supplies visual cues about the type of data being entered or displayed.

The Masked Edit control generally behaves as a standard text box control with enhancements for optional masked input and formatted output. If you don't use an input mask, the Masked Edit control behaves much like a standard text box.

If you define an input mask, each character position in the Masked Edit control maps to either a placeholder of a specified type or a literal character. Literal characters, or literals, can give visual cues about the type of data being used. For example, the parentheses surrounding the area code of a telephone number are literals: (206).

If you attempt to enter a character that conflicts with the input mask, the control generates a ValidationError beep. We could throw an exception but I think this is too heavy. The input mask prevents you from entering invalid characters into the control.   When you define an input mask, the Masked Edit control behaves differently from the standard text box. The insertion point automatically skips over literals as you enter data or move the insertion point. 

When you insert or delete a character, all nonliteral characters to the right of the insertion point are shifted, as necessary. If shifting these characters leads to a validation error, the insertion or deletion is prevented, and a ValidationError beep is triggered.

Suppose the Mask property is defined as "?###", and the current value of the Text property is "A12."  If you attempt to insert the letter "B" to the left of the letter "A," the "A" would shift to the right. Since the second value of the input mask requires a number, the letter "A" would cause the control to generate a ValidationError beep. 

The Masked Edit control also validates the parameter value of the SetInputText function the user passes at run time. If you use the SetInputText function so that it conflicts with the input mask, the function will return an errorcode. 

You may select text in the same way as for a standard text box control. When selected text is deleted, the control attempts to shift the remaining characters to the right of the selection. However, any remaining character that might cause a validation error during this shift is deleted, and no ValidationError beep is generated. 

Normally, when a selection in the Masked Edit control is copied onto the Clipboard, the entire selection, including literals, is transferred onto the Clipboard. You can use the SetClipMode function to define the behavior for transferring only user-entered data onto the Clipboard or not - literal characters that are part of the input mask are not copied.