Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The MaskedTextBox control will optionally validate user input against the type defined by its MaskedTextBox.ValidatingType property. When this property is not null, the following series of events occurs:
The validation sequence begins when one of the following occurs:
Any of these events result in a call to the Parse method of the type specified with the ValidatingType property. Parse is responsible for the conversion of the formatted input string to the target type. A successful conversion equates to a successful validation.
After the event handler for the Validating, is raised. A handler can be implemented to perform standard validation, perhaps including canceling the event.event returns, the standard validation event,
If the event is not canceled in step 3, the standard control validation event Validated is raised.
If the Cancel property is set to true in the event handler, the event will be canceled and the MaskedTextBox control retains focus, unless the subsequent Validating event sets its version of the CancelEventArgs.Cancel property back to false.
The following code example attempts to parse the user's input as a valid DateTime object. If it fails, the event handler displays an error message to the user. If the value is a valid DateTime, the code verifies that the date supplied is not prior to today's date. This code example requires that your Windows Forms project contains a MaskedTextBox control named MaskedTextBox1 and a ToolTip control named ToolTip1.
Available since 2.0