AutomationEventHandler AutomationEventHandler AutomationEventHandler AutomationEventHandler Delegate

정의

UI 자동화 공급자에서 발생하는 이벤트를 처리하기 위해 UI 자동화 클라이언트 애플리케이션에서 구현하는 메서드를 나타냅니다.Represents the method implemented by the UI Automation client application to handle an event raised by a UI Automation provider.

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 Object Object Object

이벤트를 발생시킨 개체입니다.The object that raised the event.

e
AutomationEventArgs AutomationEventArgs AutomationEventArgs AutomationEventArgs

이벤트 정보입니다.Information about the event.

상속
AutomationEventHandlerAutomationEventHandlerAutomationEventHandlerAutomationEventHandler

예제

다음 예제에서는 구독 하 고 이벤트를 처리 하는 방법을 보여 줍니다.The following example shows how to subscribe to and handle an event.

// 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 자동화UI Automation 이벤트입니다.Use an AutomationEventHandler delegate to specify the method that is called by a client to handle UI 자동화UI Automation events.

합니다 AutomationElement 나타내는 sender 수 있는 모든 캐시 되지 속성 또는 애플리케이션이이 이벤트를 구독 하는지 여부에 따라 패턴을 CacheRequest 활성 상태 였던 합니다.The AutomationElement represented by sender might not have any cached properties or patterns, depending on whether the application subscribed to this event while a CacheRequest was active.

확장 메서드

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.Gets an object that represents the method represented by the specified delegate.

적용 대상

추가 정보