InvokePattern.Invoke 方法

定義

傳送要求以啟動控制項,並啟始其單一明確的動作。

public:
 void Invoke();
public void Invoke ();
member this.Invoke : unit -> unit
Public Sub Invoke ()

例外狀況

此項目不支援 InvokePattern 控制項模式,或是處於隱藏或封鎖狀態。

項目未啟用。 當使用者介面自動化提供者對 IsEnabled 屬性已實作自己的處理方式時會引發。

範例

在下列範例中, InvokePattern 會從 控制項取得控制項模式,並 Invoke 呼叫 方法。

///--------------------------------------------------------------------
/// <summary>
/// Obtains an InvokePattern control pattern from a control
/// and calls the InvokePattern.Invoke() method on the control.
/// </summary>
/// <param name="targetControl">
/// The control of interest.
/// </param>
///--------------------------------------------------------------------
private void InvokeControl(AutomationElement targetControl)
{
    InvokePattern invokePattern = null;

    try
    {
        invokePattern =
            targetControl.GetCurrentPattern(InvokePattern.Pattern)
            as InvokePattern;
    }
    catch (ElementNotEnabledException)
    {
        // Object is not enabled
        return;
    }
    catch (InvalidOperationException)
    {
        // object doesn't support the InvokePattern control pattern
        return;
    }

    invokePattern.Invoke();
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains an InvokePattern control pattern from a control
''' and calls the InvokePattern.Invoke() method on the control.
''' </summary>
''' <param name="targetControl">
''' The control of interest.
''' </param>
'''--------------------------------------------------------------------
Private Sub InvokeControl(ByVal targetControl As AutomationElement) 
    Dim invokePattern As InvokePattern = Nothing
    
    Try
        invokePattern = _
        DirectCast(targetControl.GetCurrentPattern(invokePattern.Pattern), _
        InvokePattern)
    Catch e As ElementNotEnabledException
        ' Object is not enabled.
        Return
    Catch e As InvalidOperationException
        ' Object doesn't support the InvokePattern control pattern
        Return
    End Try
    
    invokePattern.Invoke()

End Sub

備註

呼叫 Invoke 應該立即傳回 ,而不會封鎖。 不過,此行為完全相依于 Microsoft 消費者介面自動化 提供者實作。 在呼叫 Invoke 會導致封鎖問題 (例如強制回應對話方塊) 個別協助程式執行緒的情況下,可能需要呼叫 方法。

適用於

另請參閱