AutomationEventHandler 대리자

정의

UI 자동화 공급자에서 발생하는 이벤트를 처리하기 위해 UI 자동화 클라이언트 애플리케이션에서 구현하는 메서드를 나타냅니다.

public delegate void AutomationEventHandler(System::Object ^ sender, AutomationEventArgs ^ e);
public delegate void AutomationEventHandler(object sender, AutomationEventArgs e);
type AutomationEventHandler = delegate of obj * AutomationEventArgs -> unit
Public Delegate Sub AutomationEventHandler(sender As Object, e As AutomationEventArgs)

매개 변수

sender
Object

이벤트를 발생시킨 개체입니다.

e
AutomationEventArgs

이벤트 정보입니다.

예제

다음 예제에서는 구독 하 고 이벤트를 처리 하는 방법을 보여 줍니다.

// Member variables.
AutomationElement ElementSubscribeButton;
AutomationEventHandler UIAeventHandler;

/// <summary>
/// Register an event handler for InvokedEvent on the specified element.
/// </summary>
/// <param name="elementButton">The automation element.</param>
public void SubscribeToInvoke(AutomationElement elementButton)
{
    if (elementButton != null)
    {
        Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent,
             elementButton, TreeScope.Element,
             UIAeventHandler = new AutomationEventHandler(OnUIAutomationEvent));
        ElementSubscribeButton = elementButton;
    }
}

/// <summary>
/// AutomationEventHandler delegate.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
private void OnUIAutomationEvent(object src, AutomationEventArgs e)
{
    // Make sure the element still exists. Elements such as tooltips
    // can disappear before the event is processed.
    AutomationElement sourceElement;
    try
    {
        sourceElement = src as AutomationElement;
    }
    catch (ElementNotAvailableException)
    {
        return;
    }
    if (e.EventId == InvokePattern.InvokedEvent)
    {
        // TODO Add handling code.
    }
    else
    {
        // TODO Handle any other events that have been subscribed to.
    }
}

private void ShutdownUIA()
{
    if (UIAeventHandler != null)
    {
        Automation.RemoveAutomationEventHandler(InvokePattern.InvokedEvent,
            ElementSubscribeButton, UIAeventHandler);
    }
}
' Member variables.
Private ElementSubscribeButton As AutomationElement
Private UIAeventHandler As AutomationEventHandler


''' <summary>
''' Register an event handler for InvokedEvent on the specified element.
''' </summary>
''' <param name="elementButton">The automation element.</param>
Public Sub SubscribeToInvoke(ByVal elementButton As AutomationElement)
    If (elementButton IsNot Nothing) Then
        UIAeventHandler = New AutomationEventHandler(AddressOf OnUIAutomationEvent)
        Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent, elementButton, _
        TreeScope.Element, UIAeventHandler)
        ElementSubscribeButton = elementButton
    End If

End Sub


''' <summary>
''' AutomationEventHandler delegate.
''' </summary>
''' <param name="src">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
Private Sub OnUIAutomationEvent(ByVal src As Object, ByVal e As AutomationEventArgs)
    ' Make sure the element still exists. Elements such as tooltips can disappear
    ' before the event is processed.
    Dim sourceElement As AutomationElement
    Try
        sourceElement = DirectCast(src, AutomationElement)
    Catch ex As ElementNotAvailableException
        Exit Sub
    End Try
    If e.EventId Is InvokePattern.InvokedEvent Then
        ' TODO Add handling code.
    Else
    End If
    ' TODO Handle any other events that have been subscribed to.
    Console.WriteLine("Event: " & e.EventId.ProgrammaticName)
End Sub

Private Sub ShutdownUIA()
    If (UIAeventHandler IsNot Nothing) Then
        Automation.RemoveAutomationEventHandler(InvokePattern.InvokedEvent, ElementSubscribeButton, UIAeventHandler)
    End If

End Sub

설명

대리자를 AutomationEventHandler 사용하여 UI 자동화 이벤트를 처리하기 위해 클라이언트에서 호출하는 메서드를 지정합니다.

합니다 AutomationElement 나타내는 sender 수 있는 모든 캐시 되지 속성 또는 애플리케이션이이 이벤트를 구독 하는지 여부에 따라 패턴을 CacheRequest 활성 상태 였던 합니다.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보