{"id":3473,"date":"2011-09-27T08:53:00","date_gmt":"2011-09-27T16:53:00","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/?p=3473"},"modified":"2011-09-27T08:53:41","modified_gmt":"2011-09-27T16:53:41","slug":"primalforms-2011-spotlight-on-the-maskedtextbox-control","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2011\/09\/27\/primalforms-2011-spotlight-on-the-maskedtextbox-control\/","title":{"rendered":"PrimalForms 2011: Spotlight on the MaskedTextBox Control"},"content":{"rendered":"<p><em>The \u201cSpotlight on Controls\u201d series focuses on a single WinForms control in PrimalForms 2011 , details the important Properties, Methods, and Events of the control and demonstrates how to utilize the control. Most of the information about the controls is still applicable to previous versions of PrimalForms.<\/em><\/p>\n<p>Last time we took a look at the <a href=\"http:\/\/www.sapien.com\/blog\/2011\/08\/18\/primalforms-2011-spotlight-on-the-errorprovider-control\/\">ErrorProvider<\/a> control. This time we will look at the MaskedTextBox control:<\/p>\n<p><span style=\"font-size: medium\"><strong>MaskedTextBox Control <\/strong>[System.Windows.Forms.MaskedTextBox]<\/span><\/p>\n<p>Represents an enhanced text box control that supports a declarative syntax for accepting or rejecting user input.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"display: inline\" title=\"MaskedTextBoxToolbox\" alt=\"MaskedTextBoxToolbox\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/09\/MaskedTextBoxToolbox.png\" width=\"106\" height=\"17\"><\/p>\n<p>Default Event: MaskInputRejected<\/p>\n<p><em>Why use a MaskedTextBox control?<\/em><\/p>\n<p>Use the MaskedTextBox to distinguish between proper and improper user input. By using a mask, you can specify the format of the input without custom validation.<\/p>\n<p><strong><span style=\"font-size: small\"><font size=\"3\"><\/font><\/span><\/strong><\/p>\n<p><strong><span style=\"font-size: small\"><font size=\"3\">Important Properties:<\/font><\/span><\/strong><\/p>\n<p><strong>Mask<\/strong>  <\/p>\n<p>This property sets the string governing the input for this control.&nbsp; <\/p>\n<p>Why use the Mask property?  <\/p>\n<p>Use the Mask property to limit the textbox\u2019s input to a specific format. You can define your own custom mask or preferably select from a predefined set using the designer. The designer has a useful set of predefined masks such as date time formats, phone numbers, and zip codes.  <\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/09\/Designer-Input-Mask.png\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Designer Input Mask\" border=\"0\" alt=\"Designer Input Mask\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/09\/Designer-Input-Mask_thumb.png\" width=\"244\" height=\"172\"><\/a><\/p>\n<p>You can access the predefined mask via the Property Pane:  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Edit Mask in Property Pane\" border=\"0\" alt=\"Edit Mask in Property Pane\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/09\/Edit-Mask-in-Property-Pane.png\" width=\"264\" height=\"87\">  <\/p>\n<p>Or directly in the designer:  <\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Edit Mask in Designer\" border=\"0\" alt=\"Edit Mask in Designer\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/09\/Edit-Mask-in-Designer.png\" width=\"375\" height=\"115\">  <\/p>\n<p>If you need to create you own format, please refer to the following table or go to the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.windows.forms.maskedtextbox.mask.aspx\">Mask Property MSDN Help Page<\/a> for more details.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"582\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"101\"><strong>Mask Element<\/strong><\/td>\n<td valign=\"top\" width=\"479\"><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">0<\/td>\n<td valign=\"top\" width=\"479\">Digit, required. This element will accept any single digit between 0 and 9.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">9<\/td>\n<td valign=\"top\" width=\"479\">Digit or space, optional. <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">#<\/td>\n<td valign=\"top\" width=\"479\">Digit or space, optional. If this position is blank in the mask, it will be rendered as a space in the Text property. Plus (+) and minus (-) signs are allowed.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">L<\/td>\n<td valign=\"top\" width=\"479\">Letter, required. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to [a-zA-Z] in regular expressions. <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">?<\/td>\n<td valign=\"top\" width=\"479\">Letter, optional. Restricts input to the ASCII letters a-z and A-Z. This mask element is equivalent to [a-zA-Z]? in regular expressions. <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">&amp;<\/td>\n<td valign=\"top\" width=\"479\">Character, required. If the AsciiOnly property is set to true, this element behaves like the &#8220;L&#8221; element. <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">C<\/td>\n<td valign=\"top\" width=\"479\">Character, optional. Any non-control character. If the AsciiOnly property is set to true, this element behaves like the &#8220;?&#8221; element.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">A<\/td>\n<td valign=\"top\" width=\"479\">Alphanumeric, required. If the AsciiOnly property is set to true, the only characters it will accept are the ASCII letters a-z and A-Z. This mask element behaves like the &#8220;a&#8221; element.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">a<\/td>\n<td valign=\"top\" width=\"479\">Alphanumeric, optional. If the AsciiOnly property is set to true, the only characters it will accept are the ASCII letters a-z and A-Z. This mask element behaves like the &#8220;A&#8221; element.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">.<\/td>\n<td valign=\"top\" width=\"479\">Decimal placeholder. The actual display character used will be the decimal symbol appropriate to the culture.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">,<\/td>\n<td valign=\"top\" width=\"479\">Thousands placeholder. The actual display character used will be the thousands placeholder appropriate to the culture.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">:<\/td>\n<td valign=\"top\" width=\"479\">Time separator. The actual display character used will be the time symbol appropriate to the culture.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">\/<\/td>\n<td valign=\"top\" width=\"479\">Date separator. The actual display character used will be the date symbol appropriate to culture.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">$<\/td>\n<td valign=\"top\" width=\"479\">Currency symbol. The actual character displayed will be the currency symbol appropriate to the culture.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">&lt;<\/td>\n<td valign=\"top\" width=\"479\">Shift down. Converts all characters that follow to lowercase. <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">&gt;<\/td>\n<td valign=\"top\" width=\"479\">Shift up. Converts all characters that follow to uppercase.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">|<\/td>\n<td valign=\"top\" width=\"479\">Disable a previous shift up or shift down.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">\\<\/td>\n<td valign=\"top\" width=\"479\">Escape. Escapes a mask character, turning it into a literal. &#8220;\\\\&#8221; is the escape sequence for a backslash. <\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"101\">All other characters<\/td>\n<td valign=\"top\" width=\"479\">Literals. All non-mask elements will appear as themselves within MaskedTextBox. Literals always occupy a static position in the mask at run time, and cannot be moved or deleted by the user.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>An example mask for a US phone number is a follows:<\/p>\n<p>(999) 000-0000<\/p>\n<p>In this mask the first three digits are optional and the last seven are required. The parentheses are considered Literals, which means the user cannot altered them.<\/p>\n<p><strong><\/strong>Resulting MaskedTextBox with Phone Number Mask:<br \/><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"MaskedTextBox using Phone Mask\" border=\"0\" alt=\"MaskedTextBox using Phone Mask\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/09\/MaskedTextBox-using-Phone-Mask.png\" width=\"288\" height=\"31\"><\/p>\n<p><strong>BeepOnError<\/strong><\/p>\n<p>This property indicates whether the masked text box control raises the system beep for each user key stroke that it rejects.<\/p>\n<p>Values (Default: <span style=\"color: #8b0000\">$False<\/span>): <\/p>\n<blockquote>\n<p><span style=\"color: #8b0000\">$True<\/span>\/ <span style=\"color: #8b0000\">$False<\/span><\/p>\n<\/blockquote>\n<p><strong>Culture<\/strong><\/p>\n<p>This property sets the culture information associated with the masked text box.<\/p>\n<p>Set this property if you are specifically targeting a culture that is not the current default (English (United States) for US machines). This effects the format of the date time entries and these changed will be reflected when selecting predefined masks as mentioned above.<\/p>\n<p><strong><\/strong>&nbsp;<\/p>\n<p><strong>MaskCompleted<\/strong><\/p>\n<p>This property indicates whether all required inputs have been entered into the input mask.<\/p>\n<p>The MaskCompleted property can be useful when it comes to validating the data. See the MaskFull property for an example.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>MaskFull<\/strong><\/p>\n<p>This property indicates whether all required and optional inputs have been entered into the input mask. <\/p>\n<p>This property is similar to MaskCompleted property with the exception that it also encompasses optional inputs specified in the Mask property. To compare these properties and to demonstrate their usefulness when it comes to validating, we will look at validating a phone number. The predefined Mask for a US phone number specifies that the area code (first three digits) is optional and the remaining seven digits are mandatory.<\/p>\n<p>The following examples will help demonstrate the difference between the two properties:<\/p>\n<p>Partially completed phone number:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Partial Phone Number\" border=\"0\" alt=\"Partial Phone Number\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/09\/Partial-Phone-Number.png\" width=\"288\" height=\"31\"><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"241\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"139\"><strong>Property<\/strong><\/td>\n<td valign=\"top\" width=\"100\"><strong>Value<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"139\">MaskCompleted<\/td>\n<td valign=\"top\" width=\"100\">False<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"139\">MaskFull<\/td>\n<td valign=\"top\" width=\"100\">False<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>Phone number without an area code:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Phone number without Area Code\" border=\"0\" alt=\"Phone number without Area Code\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/09\/Phone-number-without-Area-Code.png\" width=\"286\" height=\"30\"><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"241\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"139\"><strong>Property<\/strong><\/td>\n<td valign=\"top\" width=\"100\"><strong>Value<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"139\">MaskCompleted<\/td>\n<td valign=\"top\" width=\"100\">True<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"139\">MaskFull<\/td>\n<td valign=\"top\" width=\"100\">False<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>Completed phone number:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Completed Phone Number\" border=\"0\" alt=\"Completed Phone Number\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/09\/Completed-Phone-Number.png\" width=\"287\" height=\"32\"><\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"2\" width=\"241\">\n<tbody>\n<tr>\n<td valign=\"top\" width=\"139\"><strong>Property<\/strong><\/td>\n<td valign=\"top\" width=\"100\"><strong>Value<\/strong><\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"139\">MaskCompleted<\/td>\n<td valign=\"top\" width=\"100\">True<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"139\">MaskFull<\/td>\n<td valign=\"top\" width=\"100\">True<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong><\/strong>&nbsp;<\/p>\n<p><strong>Text<\/strong><\/p>\n<p>The property gets or sets the text as it is currently displayed to the user.&nbsp; <\/p>\n<p>The value returned may include formatting characters specified in the Mask property. See the TextMaskFormat property for more information. <\/p>\n<p><strong><\/strong>&nbsp;<\/p>\n<p><strong>Text<strong>Mask<\/strong>Format<\/strong><\/p>\n<p>This property determines whether the string returned by the Text property includes literals and\/or prompt characters.<\/p>\n<p>Use the TextMaskFormat if you need to modify the format of the string that is returned by the Text property of the MaskedTextBox control.<\/p>\n<p>Values (Default: <em>IncludeLiterals<\/em>):<\/p>\n<p>The example values displayed are based on he following MaskTextBox:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px\" title=\"Phone number without Area Code\" border=\"0\" alt=\"Phone number without Area Code\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2011\/09\/Phone-number-without-Area-Code1.png\" width=\"286\" height=\"30\"><\/p>\n<blockquote>\n<p><em>IncludePrompt<\/em><br \/>Return text input by the user as well as any instances of the prompt character.<\/p>\n<p>Text: <font color=\"#ff0000\">&#8220;___5555555&#8221;<\/font><\/p>\n<p><em>IncludeLiterals<\/em><br \/>Return text input by the user as well as any literal characters defined in the mask.  <\/p>\n<p>Text: <font color=\"#ff0000\">&#8220;(&nbsp;&nbsp; ) 555-5555&#8221;<\/font>  <\/p>\n<p><em>IncludePromptAndLiterals<\/em><br \/>Return text input by the user as well as any literal characters defined in the mask and any instances of the prompt character.  <\/p>\n<p>Text:&nbsp; <font color=\"#ff0000\">&#8220;(___) 555-5555&#8221;<\/font>  <\/p>\n<p><em>ExcludePromptAndLiterals<\/em><br \/>Return only text input by the user.  <\/p>\n<p>Text: <font color=\"#ff0000\">&#8221;&nbsp;&nbsp; 5555555&#8243;<strong><\/strong><\/font><\/p>\n<\/blockquote>\n<p><strong>ValidatingType<\/strong><\/p>\n<p>This property contains the data type used to verify the data input by the user. <\/p>\n<p><strong><font size=\"3\"><\/font><\/strong>You need not set this property normally, since the preset Masks already set this property appropriately. This ensures data types are within the correct range. For example \u201c77\/77\/7777\u201d is a valid format for a date, but the value is not. <\/p>\n<p>You must set the ValidatingType property to a type, which in PowerShell is defined by the full class name surrounded by brackets. For example, to set the ValidatingType to a DateTime you will need to do the following:<\/p>\n<pre><span style=\"color: #8b0000\">$maskedtextboxBirthDate<\/span><span style=\"color: #000000\">.ValidatingType <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> [System.DateTime]<\/span><\/pre>\n<p>Again you need not set this property if you are using a predefined mask. <\/p>\n<p>Note: The ValidatingType property looks for a static method named \u201cParse\u201d that must be present in the Type to validate the content. Since the DateTime class has a Parse method, it is compatible:<\/p>\n<blockquote>\n<p>[System.DateTime]::Parse()<\/p>\n<\/blockquote>\n<p><strong><font size=\"3\"><\/font><\/strong>Other Common Types with the Parse static method includes the all the basic value types, such as:<\/p>\n<blockquote>\n<p>[Int]<\/p>\n<p>[Double]<\/p>\n<p>[Float]<\/p>\n<\/blockquote>\n<p>All enumerators are compatible, such as:<\/p>\n<blockquote>\n<p>[System.Windows.Forms.DialogResult]<\/p>\n<p>[Microsoft.PowerShell.ExecutionPolicy]<\/p>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p><strong><font size=\"3\">Important Methods:<\/font><\/strong><\/p>\n<p><strong>ValidateText<\/strong><\/p>\n<p>This method converts the user input string to an instance of the validating type.<\/p>\n<p><strong><font size=\"3\"><\/font><\/strong>Use this method to determine if the content of the MaskTextBox is valid. This method requires that a compatible type be set in the ValdiatingType property. If the ValidateText fails it will return a <span style=\"color: #8b0000\">$null <\/span>value otherwise it will return an object of the corresponding type.<\/p>\n<p><font size=\"3\">Example:<\/font><\/p>\n<pre><span style=\"color: #000000\">    <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">$maskedtextboxBirthDate<\/span><span style=\"color: #000000\">.ValidatingType <\/span><span style=\"color: #0000ff\">-ne<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$null<\/span><span style=\"color: #000000\">)\n    {\n        <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">$maskedtextboxBirthDate<\/span><span style=\"color: #000000\">.ValidateText() <\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$null<\/span><span style=\"color: #000000\">)\n        {\n            <\/span><span style=\"color: #008000\">#Validation Failed<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #000000\">}\n        <\/span><span style=\"color: #0000ff\">else<\/span><span style=\"color: #000000\">\n        {\n            <\/span><span style=\"color: #008000\">#Validation Successful<\/span><span style=\"color: #000000\">  \n        }\n    }\n<\/span><\/pre>\n<p><font size=\"3\">Note: The MaskTextBox will automatically validate the text when it loses focus. <\/font><\/p>\n<p><strong><font size=\"3\"><\/font><\/strong>&nbsp;<\/p>\n<p><strong><font size=\"3\">Important&nbsp; Events:<\/font><\/strong><\/p>\n<p><strong>MaskInputRejected<\/strong><\/p>\n<p>This event occurs when the user&#8217;s input or assigned character does not match the corresponding format element of the input mask.<\/p>\n<p>Use this event when you want to react to invalid input:<\/p>\n<pre><span style=\"color: #8b0000\">$maskedtextboxPhone_MaskInputRejected<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">[System.Windows.Forms.MaskInputRejectedEventHandler]{\n<\/span><span style=\"color: #008000\">#Event Argument: $_ = [System.Windows.Forms.MaskInputRejectedEventArgs]    <\/span><span style=\"color: #000000\">\n    <\/span><span style=\"color: #8b0000\">$labelError<\/span><span style=\"color: #000000\">.Text <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #ff0000\">\"Failed input -Postion ({0}): {1}\"<\/span><span style=\"color: #000000\">  <\/span><span style=\"color: #0000ff\">-f<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.Position, <\/span><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.RejectionHint.ToString()\n}<\/span><\/pre>\n<p>The event passes a parameter variable <span style=\"color: #8b0000\">$_<\/span> . Use this variable to access the following properties:<\/p>\n<blockquote>\n<p><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.Position<\/span><\/p>\n<p>Returns the position in the mask corresponding to the invalid input character.<\/p>\n<\/blockquote>\n<blockquote>\n<p><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.RejectionHint<\/span><\/p>\n<p>Returns an enumerated value [System.ComponentModel.MaskedTextResultHint] that describes why the input character was rejected. Please see the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.componentmodel.maskedtextresulthint.aspx\">MSDN MaskTextResultHist Help page<\/a> for more information.<\/p>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p><strong>TypeValidationCompleted<\/strong><\/p>\n<p>This event occurs when MaskedTextBox has finished parsing the current value using the ValidatingType property.<\/p>\n<p>Use this event in order to react to when a type validation fails or succeeds. This event is also fired when the ValdiateText method is called.<\/p>\n<pre><span style=\"color: #8b0000\">$maskedtextboxBirthDate_TypeValidationCompleted<\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\">[System.Windows.Forms.TypeValidationEventHandler]{\n<\/span><span style=\"color: #008000\">#Event Argument: $_ = [System.Windows.Forms.TypeValidationEventArgs]<\/span><span style=\"color: #000000\">\n    <\/span><span style=\"color: #0000ff\">if<\/span><span style=\"color: #000000\">(<\/span><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.IsValidInput <\/span><span style=\"color: #0000ff\">-eq<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$false<\/span><span style=\"color: #000000\">)\n    {\n        <\/span><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.Cancel <\/span><span style=\"color: #0000ff\">=<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #8b0000\">$true<\/span><span style=\"color: #000000\"> <\/span><span style=\"color: #008000\">#Keep the focus on the control<\/span><span style=\"color: #000000\">\n        <\/span><span style=\"color: #8b0000\">$errorprovider1<\/span><span style=\"color: #000000\">.SetError(<\/span><span style=\"color: #8b0000\">$maskedtextboxBirthDate<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #ff0000\">\"Invalid Date Format\"<\/span><span style=\"color: #000000\">);\n    }\n    <\/span><span style=\"color: #0000ff\">else<\/span><span style=\"color: #000000\">\n    {\n        <\/span><span style=\"color: #8b0000\">$errorprovider1<\/span><span style=\"color: #000000\">.SetError(<\/span><span style=\"color: #8b0000\">$maskedtextboxBirthDate<\/span><span style=\"color: #000000\">, <\/span><span style=\"color: #ff0000\">\"\"<\/span><span style=\"color: #000000\">);    \n    }\n}<\/span><\/pre>\n<p>The TypeValdiationCompleted passes a parameter variable <span style=\"color: #8b0000\">$_<\/span>. The following are important properties you can access with this variable:<\/p>\n<blockquote>\n<p><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.Cancel <\/span><\/p>\n<p>This property indicates whether the event should be canceled. Set it to <span style=\"color: #8b0000\">$true <\/span>to retain the focus on the MaskTextBox.<\/p>\n<p><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.IsValidInput <\/span><\/p>\n<p>This property indicates whether the formatted input string was successfully converted to the validating type.<\/p>\n<p><span style=\"color: #8b0000\">$_<\/span><span style=\"color: #000000\">.ReturnValue <\/span><\/p>\n<p>This property returns the object that results from the conversion of the formatted input string.<\/p>\n<\/blockquote>\n<p>&nbsp;<\/p>\n<p>For an example use of the MaskTextBox, please refer to the samples used in the&nbsp; <a href=\"http:\/\/www.sapien.com\/blog\/?s=%22Validating+the+Form%22\">PrimalForms 2011:&nbsp; Validating the Form<\/a> blog articles.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The \u201cSpotlight on Controls\u201d series focuses on a single WinForms control in PrimalForms 2011 , details the important Properties, Methods, and Events of the control and demonstrates how to utilize the control. Most of the information about the controls is still applicable to previous versions of PrimalForms. Last time we took a look at the [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[509,575,644,25],"tags":[641,687,28,633,327],"class_list":["post-3473","post","type-post","status-publish","format-standard","hentry","category-primalforms-software-news","category-primalforms-2011-software-news","category-spotlight-on-controls","category-windows-powershell","tag-controls","tag-maskedtextbox","tag-powershell","tag-primalforms-2011","tag-winform"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3473","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=3473"}],"version-history":[{"count":4,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3473\/revisions"}],"predecessor-version":[{"id":3480,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/3473\/revisions\/3480"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=3473"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=3473"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=3473"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}