TypeValidationEventArgs.Cancel Właściwość

Definicja

Pobiera lub ustawia wartość wskazującą, czy zdarzenie powinno zostać anulowane.

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

Wartość właściwości

true jeśli zdarzenie powinno zostać anulowane i fokus zachowany przez kontrolkę MaskedTextBox ; w przeciwnym razie, false aby kontynuować przetwarzanie walidacji.

Przykłady

Poniższy przykład kodu przedstawia użycie tego elementu członkowskiego. W tym przykładzie program obsługi zdarzeń zgłasza wystąpienie zdarzenia MaskedTextBox.TypeValidationCompleted . Ten raport pomaga dowiedzieć się, kiedy wystąpi zdarzenie i może pomóc w debugowaniu. Aby zgłosić wiele zdarzeń lub zdarzeń, które występują często, rozważ zastąpienie MessageBox.Show komunikatu ciągiem Console.WriteLine lub dołączeniem go do wielowierszowego TextBoxelementu .

Aby uruchomić przykładowy kod, wklej go w projekcie zawierającym wystąpienie typu MaskedTextBox o nazwie MaskedTextBox1. Następnie upewnij się, że program obsługi zdarzeń jest skojarzony ze zdarzeniem 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

Uwagi

Zdarzenie TypeValidationCompleted występuje tuż przed zdarzeniem Validating .

Cancel Ustawienie właściwości na true wartość w procedurze TypeValidationCompleted obsługi zdarzeń spowoduje anulowanie zdarzenia, co spowoduje MaskedTextBox zachowanie fokusu kontrolki, chyba że kolejne Validating zdarzenie ustawia jego wersję CancelEventArgs.Cancel właściwości na false.

Dotyczy

Zobacz też