Export (0) Print
Expand All

WindowPattern.WindowOpenedEvent Field

Identifies the event that is raised when a window is opened.

Namespace:  System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

'Declaration
Public Shared ReadOnly WindowOpenedEvent As AutomationEvent

This identifier is used by UI Automation client applications. UI Automation providers should use the equivalent field in WindowPatternIdentifiers.

In the following example, event listeners are declared and an AutomationEventHandler delegate is specified for WindowOpenedEvent and WindowClosedEvent events.

'''------------------------------------------------------------------------ 
''' <summary> 
''' Register for events of interest. 
''' </summary> 
''' <param name="targetControl"> 
''' The automation element of interest. 
''' </param> 
'''------------------------------------------------------------------------ 
Private Sub RegisterForEvents(ByVal targetControl As AutomationElement)
    Dim eventHandler As AutomationEventHandler = AddressOf OnWindowOpenOrClose
    Automation.AddAutomationEventHandler(WindowPattern.WindowClosedEvent, _
        targetControl, TreeScope.Element, eventHandler)
    Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, _
        targetControl, TreeScope.Element, eventHandler)
End Sub 'RegisterForEvents

'''------------------------------------------------------------------------ 
''' <summary> 
''' AutomationEventHandler delegate. 
''' </summary> 
''' <param name="src">Object that raised the event.</param> 
''' <param name="e">Event arguments.</param> 
'''------------------------------------------------------------------------ 
Private Sub OnWindowOpenOrClose(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 
        Return 
    End Try 

    If e.EventId Is WindowPattern.WindowOpenedEvent Then 
        ' TODO: event handling 
        Return 
    End If 
    If e.EventId Is WindowPattern.WindowClosedEvent Then 
        ' TODO: event handling 
        Return 
    End If 
End Sub 'OnWindowOpenOrClose

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft