MaskedTextBox.TypeValidationCompleted イベント
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As MaskedTextBox Dim handler As TypeValidationEventHandler AddHandler instance.TypeValidationCompleted, handler
public: event TypeValidationEventHandler^ TypeValidationCompleted { void add (TypeValidationEventHandler^ value); void remove (TypeValidationEventHandler^ value); }

MaskedTextBox コントロールは、MaskedTextBox.ValidatingType プロパティで定義された型に対してオプションでユーザー入力を検証します。このプロパティが null 参照 (Visual Basic では Nothing) 以外の場合、次の一連のイベントが発生します。
-
これらのイベントが発生すると、ValidatingType プロパティで指定された型の Parse メソッドが呼び出されます。書式設定された入力文字列は、Parse によって目的の型に変換されます。変換に成功した場合、それは検証に成功したのと同義です。
-
Parse から制御が戻ると、TypeValidationCompleted イベントが発生します。このイベントのイベント ハンドラは、通常は型またはマスクの検証処理を実行するために実装されます。このイベント ハンドラは、変換に関する情報を格納する TypeValidationEventArgs パラメータを受け取ります。たとえば、IsValidInput メンバは、変換が正常に行われたかどうかを示します。
-
TypeValidationCompleted イベントのイベント ハンドラから制御が戻ると、標準の検証イベントである Validating が発生します。イベントのキャンセルなど、標準の検証を実行するためのハンドラを実装できます。
-
手順 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); }

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からMaskedTextBox.TypeValidationCompleted イベントを検索する場合は、下記のリンクをクリックしてください。

- MaskedTextBox.TypeValidationCompleted イベントのページへのリンク