MaskedTextBox.TypeValidationCompleted イベントとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > MaskedTextBox.TypeValidationCompleted イベントの意味・解説 

MaskedTextBox.TypeValidationCompleted イベント

メモ : このイベントは、.NET Framework version 2.0 で新しく追加されたものです。

MaskedTextBox が ValidatingType プロパティを使用して現在の値の解析を完了した場合に発生します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Event TypeValidationCompleted As
 TypeValidationEventHandler
Dim instance As MaskedTextBox
Dim handler As TypeValidationEventHandler

AddHandler instance.TypeValidationCompleted, handler
public event TypeValidationEventHandler TypeValidationCompleted
public:
event TypeValidationEventHandler^ TypeValidationCompleted {
    void add (TypeValidationEventHandler^ value);
    void remove (TypeValidationEventHandler^ value);
}
/** @event */
public void add_TypeValidationCompleted (TypeValidationEventHandler
 value)

/** @event */
public void remove_TypeValidationCompleted
 (TypeValidationEventHandler value)
JScript では、イベントは使用できますが、新規に宣言することはできません。
解説解説

MaskedTextBox コントロールは、MaskedTextBox.ValidatingType プロパティで定義された型に対してオプションでユーザー入力を検証します。このプロパティが null 参照 (Visual Basic では Nothing) 以外の場合、次の一連のイベントが発生します。

  1. 検証シーケンスは、次のいずれかが発生したときに開始します。

  2. これらのイベントが発生すると、ValidatingType プロパティで指定された型の Parse メソッドが呼び出されます。書式設定された入力文字列は、Parse によって目的の型に変換されます。変換に成功した場合、それは検証に成功したのと同義です。

  3. Parse から制御が戻ると、TypeValidationCompleted イベントが発生します。このイベントのイベント ハンドラは、通常は型またはマスクの検証処理を実行するために実装されます。このイベント ハンドラは、変換に関する情報を格納する TypeValidationEventArgs パラメータを受け取ります。たとえば、IsValidInput メンバは、変換が正常に行われたかどうかを示します。

  4. TypeValidationCompleted イベントのイベント ハンドラから制御が戻ると、標準の検証イベントである Validating が発生します。イベントのキャンセルなど、標準の検証を実行するためのハンドラを実装できます。

  5. 手順 3 でイベントがキャンセルされなかった場合は、標準のコントロール検証イベントである Validated が発生します。

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

使用例使用例

ユーザーの入力を有効な DateTime オブジェクトとして解析するコード例を次に示します。失敗した場合、TypeValidationCompleted イベント ハンドラはユーザーにエラー メッセージを表示します。値が有効な DateTime の場合、指定された日付が今日の日付より前でないことが確認されます。このコード例は、Windows フォーム プロジェクトに、MaskedTextBox1 という名前の MaskedTextBox コントロールと、ToolTip1 という名前の ToolTip コントロールが配置されていることを前提としています。

Private Sub Form1_Load(ByVal
 sender As System.Object, ByVal e As
 System.EventArgs) Handles MyBase.Load
    Me.MaskedTextBox1.Mask = "00/00/0000"
    Me.MaskedTextBox1.ValidatingType = GetType(System.DateTime)

    Me.ToolTip1.IsBalloon = True
End Sub

Private Sub MaskedTextBox1_TypeValidationCompleted(ByVal
 sender As Object, ByVal
 e As TypeValidationEventArgs) Handles MaskedTextBox1.TypeValidationCompleted
    If (Not e.IsValidInput) Then
        Me.ToolTip1.ToolTipTitle = "Invalid
 Date"
        Me.ToolTip1.Show("The data you supplied
 must be a valid date in the format mm/dd/yyyy.", Me.MaskedTextBox1,
 Me.MaskedTextBox1.Location.X, Me.MaskedTextBox1.Location.Y, 5000)
    Else
        ' Now that the type has passed basic type validation, enforce
 more specific type rules.
        Dim UserDate As DateTime = CDate(e.ReturnValue)
        If (UserDate < DateTime.Now) Then
            Me.ToolTip1.ToolTipTitle = "Invalid
 Date"
            Me.ToolTip1.Show("The date
 in this field must be greater than today's date.",
 Me.MaskedTextBox1, Me.MaskedTextBox1.Location.X, Me.MaskedTextBox1.Location.Y, 5000)
            e.Cancel = True
        End If
    End If
End Sub

' Hide the tooltip if the user starts typing again before the five-second
 display limit on the tooltip expires.
Private Sub MaskedTextBox1_KeyDown(ByVal
 sender As Object, ByVal
 e As KeyEventArgs) Handles MaskedTextBox1.KeyDown
    Me.ToolTip1.Hide(Me.MaskedTextBox1)
End Sub
private void Form1_Load(object sender, EventArgs
 e)
{
    maskedTextBox1.Mask = "00/00/0000";
    maskedTextBox1.ValidatingType = typeof(System.DateTime);
    maskedTextBox1.TypeValidationCompleted += new TypeValidationEventHandler(maskedTextBox1_TypeValidationCompleted);
    maskedTextBox1.KeyDown += new KeyEventHandler(maskedTextBox1_KeyDown);

    toolTip1.IsBalloon = true;
}

void maskedTextBox1_TypeValidationCompleted(object sender, TypeValidationEventArgs
 e)
{
    if (!e.IsValidInput)
    {
        toolTip1.ToolTipTitle = "Invalid Date";
        toolTip1.Show("The data you supplied must be a valid date in
 the format mm/dd/yyyy.", maskedTextBox1, maskedTextBox1.Location.X, maskedTextBox1.Location.Y,
 5000);
    }
    else
    {
        //Now that the type has passed basic type validation, enforce
 more specific type rules.
        DateTime userDate = (DateTime)e.ReturnValue;
        if (userDate < DateTime.Now)
        {
            toolTip1.ToolTipTitle = "Invalid Date";
            toolTip1.Show("The date in this
 field must be greater than today's date.", maskedTextBox1, maskedTextBox1.Location.X,
 maskedTextBox1.Location.Y, 5000);
            e.Cancel = true;
        }
    }
}

// Hide the tooltip if the user starts typing again before the five-second
 display limit on the tooltip expires.
void maskedTextBox1_KeyDown(object sender, KeyEventArgs e)
{
    toolTip1.Hide(maskedTextBox1);
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MaskedTextBox クラス
MaskedTextBox メンバ
System.Windows.Forms 名前空間
MaskedTextBox.Text プロパティ
ValidateText
MaskedTextBox.ValidatingType プロパティ
TypeValidationEventArgs



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「MaskedTextBox.TypeValidationCompleted イベント」の関連用語

MaskedTextBox.TypeValidationCompleted イベントのお隣キーワード

   

英語⇒日本語
日本語⇒英語
   



MaskedTextBox.TypeValidationCompleted イベントのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS