次の方法で共有


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 コントロールによってフォーカスを保持する必要がある場合は a0/>。それ以外の場合は、検証処理を続行 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 イベントの直前に発生します。

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

適用対象

こちらもご覧ください