Share via


UI 자동화 공급자에서 이벤트 발생

업데이트: 2007년 11월

이 항목에는 UI 자동화 공급자에서 이벤트를 발생시키는 방법을 보여 주는 예제 코드가 있습니다.

예제

다음 예제의 경우 사용자 지정 단추 컨트롤 구현에서 UI 자동화 이벤트가 발생합니다. 이 구현을 통해 UI 자동화 클라이언트 응용 프로그램이 단추 클릭을 시뮬레이션할 수 있습니다.

필요 없는 처리 작업을 방지하기 위해 예제에서는 ClientsAreListening을 확인하여 이벤트를 발생시킬지 여부를 결정합니다.

''' <summary>
''' Responds to a button click, regardless of whether it was caused by a 
''' mouse or keyboard click or by InvokePattern.Invoke. 
''' </summary>
Private Sub OnCustomButtonClicked()

    '' TODO  Perform program actions invoked by the control.

    '' Raise an event.
    If AutomationInteropProvider.ClientsAreListening Then
        Dim args As AutomationEventArgs = _
            New AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent)
        AutomationInteropProvider.RaiseAutomationEvent( _
            InvokePatternIdentifiers.InvokedEvent, Me, args)
    End If
End Sub
/// <summary>
/// Responds to a button click, regardless of whether it was caused by a mouse or
/// keyboard click or by InvokePattern.Invoke. 
/// </summary>
private void OnCustomButtonClicked()
{
    // TODO  Perform program actions invoked by the control.

    // Raise an event.
    if (AutomationInteropProvider.ClientsAreListening)
    {
        AutomationEventArgs args = new AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent);
        AutomationInteropProvider.RaiseAutomationEvent(InvokePatternIdentifiers.InvokedEvent, this, args);
    }
}

참고 항목

개념

UI 자동화 공급자 개요