Automation.AddStructureChangedEventHandler 메서드

정의

구조 변경 이벤트를 처리할 메서드를 등록합니다.

public:
 static void AddStructureChangedEventHandler(System::Windows::Automation::AutomationElement ^ element, System::Windows::Automation::TreeScope scope, System::Windows::Automation::StructureChangedEventHandler ^ eventHandler);
public static void AddStructureChangedEventHandler (System.Windows.Automation.AutomationElement element, System.Windows.Automation.TreeScope scope, System.Windows.Automation.StructureChangedEventHandler eventHandler);
static member AddStructureChangedEventHandler : System.Windows.Automation.AutomationElement * System.Windows.Automation.TreeScope * System.Windows.Automation.StructureChangedEventHandler -> unit
Public Shared Sub AddStructureChangedEventHandler (element As AutomationElement, scope As TreeScope, eventHandler As StructureChangedEventHandler)

매개 변수

element
AutomationElement

이벤트 처리기를 연결할 UI 자동화 요소입니다.

scope
TreeScope

처리할 이벤트의 범위입니다. 즉, 요소 자체에서만 발생할 수도 있고 상위 및 하위 요소에서 발생할 수도 있습니다.

eventHandler
StructureChangedEventHandler

구조 변경 이벤트가 발생할 때 호출할 메서드입니다.

예제

다음 예제에서는 지정된 변경의 하위 트리가 변경될 때마다 호출되는 구조 변경 이벤트 AutomationElement 처리기 대리자를 보여줍니다.

/// <summary>
/// Handles structure-changed events. If a new app window has been added, this method ensures
/// it's in the list of runtime IDs and subscribed to window-close events.
/// </summary>
/// <param name="sender">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
/// <remarks>
/// An exception can be thrown by the UI Automation core if the element disappears
/// before it can be processed -- for example, if a menu item is only briefly visible. 
/// This exception cannot be caught here because it crosses native/managed boundaries. 
/// In the debugger, you can ignore it and continue execution. The exception does not cause
/// a break when the executable is being run.
/// </remarks>
private void OnStructureChanged(object sender, StructureChangedEventArgs e)
{
    AutomationElement element = sender as AutomationElement;

    if (e.StructureChangeType == StructureChangeType.ChildAdded)
    {
        Object windowPattern;
        if (false == element.TryGetCurrentPattern(WindowPattern.Pattern, out windowPattern))
        {
            return;
        }
        int[] rid = e.GetRuntimeId();
        if (RuntimeIdListed(rid, savedRuntimeIds) < 0)
        {
            AddToWindowHandler(element);
            savedRuntimeIds.Add(rid);
        }
    }
}
''' <summary>
''' Handles structure-changed events. If a new app window has been added, this method ensures
''' it's in the list of runtime IDs and subscribed to window-close events.
''' </summary>
''' <param name="sender">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
''' <remarks>
''' An exception can be thrown by the UI Automation core if the element disappears
''' before it can be processed -- for example, if a menu item is only briefly visible. 
''' This exception cannot be caught here because it crosses native/managed boundaries. 
''' In the debugger, you can ignore it and continue execution. The exception does not cause
''' a break when the executable is being run.
''' </remarks>
Private Sub OnStructureChanged(ByVal sender As Object, ByVal e As StructureChangedEventArgs) 

    Dim element As AutomationElement = DirectCast(sender, AutomationElement)
    If e.StructureChangeType = StructureChangeType.ChildAdded Then
        Dim myWindowPattern As Object = Nothing
        If False = element.TryGetCurrentPattern(WindowPattern.Pattern, myWindowPattern) Then
            Return
        End If
        Dim rid As Integer() = e.GetRuntimeId()
        If RuntimeIdListed(rid, savedRuntimeIds) < 0 Then
            AddToWindowHandler(element)
            savedRuntimeIds.Add(rid)
        End If
    End If
 
End Sub

다음 예제 코드는 대리자의 인스턴스를 추가합니다.

// elementRoot is an AutomationElement.
Automation.AddStructureChangedEventHandler(elementRoot, TreeScope.Children, 
    new StructureChangedEventHandler(OnStructureChanged));
' elementRoot is an AutomationElement.
Automation.AddStructureChangedEventHandler(elementRoot, TreeScope.Children, New StructureChangedEventHandler(AddressOf OnStructureChanged))

설명

eventHandler는 메서드의 인스턴스이거나 메서드에 대한 참조(AddressOfVisual Basic)일 수 있습니다.

적용 대상

추가 정보