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

참고 항목

이 설명서는 System.Windows.Automation 네임스페이스에 정의된 관리되는 UI 자동화 클래스를 사용하려는 .NET Framework 개발자를 위한 것입니다. UI 자동화에 대한 최신 정보는 Windows 자동화 API: UI 자동화를 참조하세요.

이 항목에는 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 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);
    }
}

참고 항목