WindowPattern.Close Method ()

 

Attempts to close the current window.

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

Public Sub Close

Exception Condition
InvalidOperationException

The control is unable to perform the requested action.

ElementNotAvailableException

When the control is no longer available.

When called on a split pane control, this method will close the pane and remove the associated split. This method may also close all other panes depending on implementation.

In the following example, a WindowPatterncontrol pattern is obtained from an AutomationElement and is subsequently used to close the AutomationElement.

'''------------------------------------------------------------------------
''' <summary>
''' Obtains a WindowPattern control pattern from an automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A WindowPattern object.
''' </returns>
'''------------------------------------------------------------------------
Private Function GetWindowPattern(ByVal targetControl As AutomationElement) As WindowPattern
    Dim windowPattern As WindowPattern = Nothing

    Try
        windowPattern = DirectCast( _
        targetControl.GetCurrentPattern(windowPattern.Pattern), _
        WindowPattern)
    Catch
        ' object doesn't support the WindowPattern control pattern
        Return Nothing
    End Try
    ' Make sure the element is usable.
    If False = windowPattern.WaitForInputIdle(10000) Then
        ' Object not responding in a timely manner
        Return Nothing
    End If
    Return windowPattern
End Function 'GetWindowPattern

'''------------------------------------------------------------------------
''' <summary>
''' Calls the WindowPattern.Close() method for an associated 
''' automation element.
''' </summary>
''' <param name="windowPattern">
''' The WindowPattern control pattern obtained from
''' an automation element.
''' </param>
'''------------------------------------------------------------------------
Private Sub CloseWindow(ByVal windowPattern As WindowPattern)
    Try
        windowPattern.Close()
    Catch
        ' object is not able to perform the requested action
        Return
    End Try

End Sub 'CloseWindow

.NET Framework
Available since 3.0
Return to top
Show: