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

プロパティ値

イベントをキャンセルし、MaskedTextBox コントロールにフォーカスを残す場合は true。検証プロセスを続行する場合は false

次のコード例では、このメンバーの使用方法を示します。 この例では、イベント ハンドラーがイベントの MaskedTextBox.TypeValidationCompleted 発生を報告します。 このレポートは、イベントが発生したタイミングを確認するのに役立ち、デバッグに役立ちます。 複数のイベントまたは頻繁に発生するイベントを報告するには、 を Console.WriteLine に置き換えるかMessageBox.Show、複数行TextBoxにメッセージを追加することを検討してください。

コード例を実行するには、 という名前MaskedTextBox1の型MaskedTextBoxのインスタンスを含むプロジェクトに貼り付けます。 次に、イベント ハンドラーがイベントに関連付けられていることを確認します 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

イベント ハンドラーで プロパティを CancelTypeValidationCompletedtrue設定すると、イベントが取り消され、後続ValidatingMaskedTextBoxイベントで プロパティのバージョンが にfalse設定されていない限り、コントロールはフォーカスをCancelEventArgs.Cancel保持します。

適用対象

こちらもご覧ください