System.Windows.Forms.MaskedTextBox.MaskInputRejected Event

Occurs when the user's input or assigned character does not match the corresponding format element of the input mask.

Syntax

public event MaskInputRejectedEventHandler MaskInputRejected

Remarks

MaskedTextBox.MaskInputRejected is the default event for the System.Windows.Forms.MaskedTextBox class.

The MaskedTextBox.MaskInputRejected event occurs when a character is rejected by the input mask. The input mask, represented by the MaskedTextBox.Mask property, is interpreted by the masked text provider associated with the control through the MaskedTextBox.MaskedTextProvider property. MaskedTextBox.MaskInputRejected is raised in the following situations:

  • An input character does not match the corresponding format element. For example, the user enters an alphabetic character when a digit is required. This is probably the most common reason why this event is raised.

  • The user is trying to input extraneous characters beyond the end of the mask either because the mask has already been filled or the current caret position has been moved to the very end of the displayed input mask string.

  • A paste operation either inserts a character that does not match its associated format element, or if the MaskedTextBox.IsOverwriteMode property is false, it shifts existing characters into new positions where they do not match their format elements.

  • A cut operation shifts existing characters to the left, and one or more characters do not match their newly associated format elements.

  • An assignment was made to the MaskedTextBox.Text property and the assigned string caused one or more mask violations.

If a string was assigned to the control that causes MaskedTextBox.MaskInputRejected to occur, no part of the string will appear in System.Windows.Forms.MaskedTextBox.

The default handling for MaskedTextBox.MaskInputRejected will play a beep sound if the MaskedTextBox.BeepOnError property is set to true. This event is often handled to implement custom error handling, for example, to move to the next user input control if the mask is full, or to display a custom error dialog box or ToolTip if the input character is invalid.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0