Share via


ContentControlBase.Validated 이벤트

콘텐츠 컨트롤의 유효성 검사가 성공적으로 완료되었을 때 발생합니다.

네임스페이스:  Microsoft.Office.Tools.Word
어셈블리:  Microsoft.Office.Tools.Word(Microsoft.Office.Tools.Word.dll)

구문

‘선언
Event Validated As EventHandler
event EventHandler Validated

설명

Validated 이벤트를 처리하여 콘텐츠 컨트롤의 유효성 검사가 성공적으로 완료된 후 코드를 실행할 수 있습니다.

콘텐츠 컨트롤의 유효성을 검사하려면 Validating 이벤트를 처리합니다. 콘텐츠 컨트롤의 유효성을 검사할 때는 컨트롤의 텍스트가 특정 조건을 만족하는지 확인합니다. 예를 들어, 전화 번호가 들어 있는 콘텐츠 컨트롤의 경우 이 컨트롤에 숫자, 괄호, 하이픈 등 적절한 문자만 있는지 확인할 수 있습니다.

이벤트 처리에 대한 자세한 내용은 이벤트 사용을 참조하십시오.

예제

다음 코드 예제에서는 Validated 및 Validating 이벤트의 이벤트 처리기를 보여 줍니다. 콘텐츠 컨트롤의 값에 대한 유효성을 검사한 후에는 Validated 이벤트에 대한 이벤트 처리기가 최종 사용자에게 메시지 상자를 표시합니다.

이 예제에서는 문서에 plainTextContentControl1이라는 PlainTextContentControl이 포함되어 있다고 가정합니다. 이 코드를 사용하려면 프로젝트의 ThisDocument 클래스에 해당 코드를 붙여넣습니다. 또한 C#의 경우 plainTextContentControl1의 Validated 및 Validating 이벤트에 이벤트 처리기를 연결해야 합니다.

이 예제는 문서 수준 사용자 지정을 위한 것입니다.

Private Sub plainTextContentControl1_Validating(ByVal sender As Object, _
    ByVal e As System.ComponentModel.CancelEventArgs) _
    Handles PlainTextContentControl1.Validating

    Dim control As Microsoft.Office.Tools.Word.PlainTextContentControl = _
        TryCast(sender, Microsoft.Office.Tools.Word.PlainTextContentControl)

    If control IsNot Nothing Then
        Dim regex As New System.Text.RegularExpressions.Regex("\d")
        If regex.IsMatch(control.Text) Then
            MessageBox.Show("Invalid name. Names cannot contain integers.")
            e.Cancel = True
        End If
    End If
End Sub

Private Sub plainTextContentControl1_Validated(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles PlainTextContentControl1.Validated

    MessageBox.Show("The name is valid.")
End Sub
void plainTextContentControl1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
    Microsoft.Office.Tools.Word.PlainTextContentControl control =
        sender as Microsoft.Office.Tools.Word.PlainTextContentControl;

    if (control != null)
    {
        System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\d");
        if (regex.IsMatch(control.Text))
        {
            MessageBox.Show("Invalid name. Names cannot contain integers.");
            e.Cancel = true;
        }
    }
}

void plainTextContentControl1_Validated(object sender, EventArgs e)
{
    MessageBox.Show("The name is valid.");
}

.NET Framework 보안

  • 직접 실행 호출자의 경우 완전히 신뢰합니다. 이 멤버는 부분적으로 신뢰할 수 있는 코드에서 사용할 수 없습니다. 자세한 내용은 부분 신뢰 코드에서 라이브러리 사용을 참조하십시오.

참고 항목

참조

ContentControlBase 인터페이스

Microsoft.Office.Tools.Word 네임스페이스