When using the masked text box, the user must know the rules to follow based on the mask in the control: dates, telephone numbers, etc. The user must also enter only the allowed characters. If the user enters an invalid character, you can make the computer produce a sound (a beep). To assist you with this, the MaskedTextBox class is equipped with a Boolean property named BeepOnError: public: property bool BeepOnError { bool get (); void set (bool value); } When this property is set to True, if the user enters an invalid character, the computer produces the beep sound: void InitializeComponent()
{
txtFunctional = gcnew MaskedTextBox;
txtFunctional->Location = Point(12, 12);
txtFunctional->Mask = "999-000-0000";
txtFunctional->BeepOnError = true;
Text = "Functional";
Controls->Add(txtFunctional);
}
Also, if the user enters an invalid character in the control, the control fires a MaskInputRejected event, which is carried by a class named MaskInputRejectedEventHandler: public: event MaskInputRejectedEventHandler^ MaskInputRejected { void add (MaskInputRejectedEventHandler^ value); void remove (MaskInputRejectedEventHandler^ value); } You can (continuously) use this event to find out whenever the user enters a wrong character so you can provide assistance.
After creating the control, you can then use it in your application. When the control comes up, it usually shows its placeholders using a specific character. The most regularly used character is the underscore. Put in reverse, the presence of the underscore indicates a placeholder. If you skip a placeholder by pressing the Space bar, an underscore displays in the space you left. This rule also apples for all other characters we reviewed. In some cases, you may want to formally use the character in the placeholder. To illustrate this, consider that you have applied a mask as &&&&&&. When the control comes up, if Fe_GT4, this would be considered as Fe GT4 (with an empty space where the _ was typed). In some cases, you may want the user to be able to enter the character of the placeholder so that Fe_GT4 would produce Fe_GT4. To assist you with this, the MaskedTextBox class is equipped with the AllowPromptAsInput Boolean property: public: property bool AllowPromptAsInput { bool get (); void set (bool value); }
By default, when the control comes up, it uses some characters, such as _, to show its placeholder(s). This allows the user to know where a character is expected and the number of characters that are expected. After the user has used the control and pressed Tab or clicked another control, the masked text box may still show its placeholders. If you want, you can hide the placeholders when the control looses focus. To assist you with this, the MaskedTextBox class is equipped with a Boolean property named HidePromptOnLeave. The default value of this property is False, which indicates that the control would always show its placeholder(s). Otherwise, you can set this property to true to hide the placeholder character when the control loses focus. Here is an example: void InitializeComponent()
{
txtFunctional = gcnew MaskedTextBox;
txtFunctional->Location = Point(12, 12);
txtFunctional->Mask = "999-000-0000";
txtFunctional->BeepOnError = true;
txtFunctional->HidePromptOnLeave = true;
Text = "Functional";
Controls->Add(txtFunctional);
}
In some cases, the user can enter less than the number of placeholders in the control. Unlike the regular text box, the user cannot enter characters beyond the number of placeholders. As a class derived from the TextBoxBase class, the masked text box is equipped with a context menu that allows the user to cut, copy, and paste. When the user performs any of these operations, you may want to control whether the mask characters would be included in the cut, copied, or pasted text. To control this, the MaskedTextBox class is equipped with a property named CutCopyMaskFormat, which is based on the MaskFormat enumeration: public: property MaskFormat CutCopyMaskFormat { MaskFormat get (); void set (MaskFormat value); } Its members are: ExcludePromptAndLiterals, IncludeLiterals, IncludePrompt, and IncludePromptAndLiterals. |
|
|||||||||
|