UI オートメーション プロバイダーからのイベントの発生

Note

このドキュメントは、System.Windows.Automation 名前空間で定義されているマネージド UI オートメーション クラスを使用する .NET Framework 開発者を対象としています。 UI オートメーションの最新情報については、Windows Automation API の「UI オートメーション」を参照してください。

このトピックには、UI オートメーション プロバイダーからイベントを発生させる方法を示すコード例が記載されています。

次の例では、カスタム ボタン コントロールの実装で UI オートメーション イベントが発生します。 実装により、UI オートメーション クライアント アプリケーションがボタンのクリックをシミュレートできるようになります。

不要な処理を回避するために、例では ClientsAreListening をチェックして、イベントが発生するかどうかを確認しています。

/// <summary>
/// Responds to a button click, regardless of whether it was caused by a mouse or
/// keyboard click or by InvokePattern.Invoke.
/// </summary>
private void OnCustomButtonClicked()
{
    // TODO  Perform program actions invoked by the control.

    // Raise an event.
    if (AutomationInteropProvider.ClientsAreListening)
    {
        AutomationEventArgs args = new AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent);
        AutomationInteropProvider.RaiseAutomationEvent(InvokePatternIdentifiers.InvokedEvent, this, args);
    }
}

関連項目