WindowPattern.Close 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
嘗試關閉目前的視窗。
public:
void Close();
public void Close ();
member this.Close : unit -> unit
Public Sub Close ()
例外狀況
控制項無法執行要求的動作。
當此控制項已無法再使用時。
範例
在下列範例中, WindowPattern 會從 AutomationElement 取得控制項模式,並接著用來關閉 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 WindowPattern GetWindowPattern(AutomationElement targetControl)
{
WindowPattern windowPattern = null;
try
{
windowPattern =
targetControl.GetCurrentPattern(WindowPattern.Pattern)
as WindowPattern;
}
catch (InvalidOperationException)
{
// object doesn't support the WindowPattern control pattern
return null;
}
// Make sure the element is usable.
if (false == windowPattern.WaitForInputIdle(10000))
{
// Object not responding in a timely manner
return null;
}
return windowPattern;
}
'''------------------------------------------------------------------------
''' <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 void CloseWindow(WindowPattern windowPattern)
{
try
{
windowPattern.Close();
}
catch (InvalidOperationException)
{
// object is not able to perform the requested action
return;
}
}
'''------------------------------------------------------------------------
''' <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
備註
在分割窗格控制項上呼叫時,此方法會關閉窗格並移除相關聯的分割。 此方法也可能根據實作關閉所有其他窗格。