次の方法で共有


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

メモメモ

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

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

使用例

次の例では、カスタム ボタン コントロールの実装によって UI Automation イベントが発生します。 この実装により、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 Sub OnCustomButtonClicked()

    '' TODO  Perform program actions invoked by the control.

    '' Raise an event.
    If AutomationInteropProvider.ClientsAreListening Then
        Dim args As AutomationEventArgs = _
            New AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent)
        AutomationInteropProvider.RaiseAutomationEvent( _
            InvokePatternIdentifiers.InvokedEvent, Me, args)
    End If
End Sub
/// <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);
    }
}

参照

概念

UI オートメーション プロバイダーの概要