MaskedTextBox.TypeValidationCompleted 이벤트

정의

MaskedTextBox에서 ValidatingType 속성을 사용하여 현재 값의 구문 분석을 완료하면 발생합니다.

public:
 event System::Windows::Forms::TypeValidationEventHandler ^ TypeValidationCompleted;
public event System.Windows.Forms.TypeValidationEventHandler TypeValidationCompleted;
public event System.Windows.Forms.TypeValidationEventHandler? TypeValidationCompleted;
member this.TypeValidationCompleted : System.Windows.Forms.TypeValidationEventHandler 
Public Custom Event TypeValidationCompleted As TypeValidationEventHandler 

이벤트 유형

예제

다음 코드 예제에서는 사용자의 입력을 유효한 DateTime 개체로 구문 분석하려고 시도합니다. 실패 TypeValidationCompleted 하면 이벤트 처리기가 사용자에게 오류 메시지를 표시합니다. 값이 유효한 DateTime경우 코드는 제공된 날짜가 오늘 날짜 이전이 아닌지 확인합니다. 이 코드 예제에서는 Windows Forms 프로젝트에 라는 컨트롤과 라는 MaskedTextBox1ToolTip1컨트롤이 ToolTip 포함되어 MaskedTextBox 야 합니다.

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, 0, -20, 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, 0, -20, 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);
}
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, 0, -20, 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, 0, -20, 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

설명

합니다 MaskedTextBox 컨트롤에 의해 정의 된 형식에 대해 사용자 입력 유효성 검사 필요에 따라는 해당 MaskedTextBox.ValidatingType 속성입니다. 이 속성이 이 아닌 null경우 다음과 같은 일련의 이벤트가 발생합니다.

  1. 유효성 검사 시퀀스는 다음 중 하나가 발생할 때 시작됩니다.

  2. 이러한 이벤트는 속성으로 Parse 지정된 형식의 메서드를 호출합니다 ValidatingType . Parse 는 형식이 지정된 입력 문자열을 대상 형식으로 변환하는 작업을 담당합니다. 성공적인 변환은 성공적인 유효성 검사와 동일합니다.

  3. 반환 후 ParseTypeValidationCompleted 이벤트가 발생합니다. 이 이벤트에 대한 이벤트 처리기는 형식 또는 마스크 유효성 검사 처리를 수행하기 위해 가장 일반적으로 구현됩니다. 변환에 TypeValidationEventArgs 대한 정보가 포함된 매개 변수를 받습니다. 예를 들어 멤버는 IsValidInput 변환에 성공했는지 여부를 나타냅니다.

  4. 이벤트에 대한 TypeValidationCompleted 이벤트 처리기가 반환되면 표준 유효성 검사 이벤트 가 Validating발생합니다. 이벤트 취소를 포함하여 표준 유효성 검사를 수행하기 위해 처리기를 구현할 수 있습니다.

  5. 3단계에서 이벤트가 취소되지 않으면 표준 컨트롤 유효성 검사 이벤트가 Validated 발생합니다.

속성이 Cancel 이벤트 처리기에서 TypeValidationCompletedtrue 설정된 경우 후속 Validating 이벤트가 속성의 버전을 로 다시 false설정하지 않는 한 이벤트가 취소되고 MaskedTextBox 컨트롤이 CancelEventArgs.Cancel 포커스를 유지합니다.

적용 대상

추가 정보