通过


TypeValidationEventArgs.Cancel 属性

定义

获取或设置一个值,该值指示是否应取消事件。

public:
 property bool Cancel { bool get(); void set(bool value); };
public bool Cancel { get; set; }
member this.Cancel : bool with get, set
Public Property Cancel As Boolean

属性值

true 如果控件应取消事件并保留 MaskedTextBox 焦点,则为 ;否则, false 继续验证处理。

示例

下面的代码示例演示了此成员的使用。 在此示例中,事件处理程序报告事件的发生情况 MaskedTextBox.TypeValidationCompleted 。 此报告可帮助你了解事件发生的时间,并可以帮助你进行调试。 若要报告多个事件或频繁发生的事件,请考虑替换MessageBox.ShowConsole.WriteLine或将消息追加到多行TextBox

若要运行示例代码,请将其粘贴到包含命名MaskedTextBox类型的MaskedTextBox1实例的项目中。 然后,确保事件处理程序与 MaskedTextBox.TypeValidationCompleted 事件相关联。

private void MaskedTextBox1_TypeValidationCompleted(Object sender, TypeValidationEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Cancel", e.Cancel );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "IsValidInput", e.IsValidInput );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Message", e.Message );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ReturnValue", e.ReturnValue );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ValidatingType", e.ValidatingType );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "TypeValidationCompleted Event" );
}
Private Sub MaskedTextBox1_TypeValidationCompleted(sender as Object, e as TypeValidationEventArgs) _ 
     Handles MaskedTextBox1.TypeValidationCompleted

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Cancel", e.Cancel)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "IsValidInput", e.IsValidInput)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "Message", e.Message)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "ReturnValue", e.ReturnValue)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "ValidatingType", e.ValidatingType)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"TypeValidationCompleted Event")

End Sub

注解

事件发生 TypeValidationCompleted 在事件之前 Validating

Cancel 属性设置为 true 事件处理程序中的 TypeValidationCompleted 属性将取消事件,导致 MaskedTextBox 控件保留焦点,除非后续 Validating 事件将属性的版本 CancelEventArgs.Cancel 设置为 false

适用于

另请参阅