Partilhar via


Automação de Eventos de Interface de Usuário para Clientes.

Observação

Esta documentação destina.Os desenvolvedores do NET Framework que desejam usar o gerenciado UI Automation classes definidas na System.Windows.Automation namespace.As informações mais recentes sobre UI Automation, consulte API de automação do Windows: Automação da interface do usuário.

This topic describes how Microsoft UI Automation events are used by UI Automation clients.

UI Automation allows clients to subscribe to events of interest. This capability improves performance by eliminating the need to continually poll all the UI elements in the system to see if any information, structure, or state has changed.

Efficiency is also improved by the ability to listen for events only within a defined scope. For example, a client can listen for focus change events on all UI Automation elements in the tree, or on just one element and its descendants.

Observação

Do not assume that all possible events are raised by a Microsoft UI Automation provider.For example, not all property changes cause events to be raised by the standard proxy providers for Windows Forms and Win32 controls.

For a broader view of UI Automation events, see Visão geral sobre eventos de automação de interface do usuário.

Este tópico contém as seguintes seções.

  • Subscribing to Events
  • Tópicos relacionados

Subscribing to Events

Client applications subscribe to events of a particular kind by registering an event handler, using one of the following methods.

Method

Event Type

Event Arguments Type

Delegate Type

AddAutomationFocusChangedEventHandler

Focus change

AutomationFocusChangedEventArgs

AutomationFocusChangedEventHandler

AddAutomationPropertyChangedEventHandler

Property change

AutomationPropertyChangedEventArgs

AutomationPropertyChangedEventHandler

AddStructureChangedEventHandler

Structure change

StructureChangedEventArgs

StructureChangedEventHandler

AddAutomationEventHandler

All other events, identified by an AutomationEvent

AutomationEventArgsouWindowClosedEventArgs

AutomationEventHandler

Before calling the method, you must create a delegate method to handle the event. If you prefer, you can handle different kinds of events in a single method, and pass this method in multiple calls to one of the methods in the table. For example, a single AutomationEventHandler can be set up to handle various events differently according to the EventId.

Observação

To process window-closed events, cast the argument type that is passed to the event handler as WindowClosedEventArgs.Because the Microsoft UI Automation element for the window is no longer valid, you cannot use the sender parameter to retrieve information; use GetRuntimeId instead.

Observação de cuidadoCuidado

If your application might receive events from its own UI, do not use your application's UI thread to subscribe to events, or to unsubscribe.Doing so might lead to unpredictable behavior.For more information, see Problemas de Threading na Automação da Interface do Usuário.

On shutdown, or when UI Automation events are no longer of interest to the application, UI Automation clients should call one of the following methods.

Method

Description

RemoveAutomationEventHandler

Unregisters an event handler that was registered by using AddAutomationEventHandler.

RemoveAutomationFocusChangedEventHandler

Unregisters an event handler that was registered by using AddAutomationFocusChangedEventHandler.

RemoveAutomationPropertyChangedEventHandler

Unregisters an event handler that was registered by using AddAutomationPropertyChangedEventHandler.

RemoveAllEventHandlers

Unregisters all registered event handlers.

For example code, see Registre-se em Eventos de Automação de Interface do Usuário.

Consulte também

Tarefas

Registre-se em Eventos de Automação de Interface do Usuário

TrackFocus Sample

Conceitos

Visão geral sobre eventos de automação de interface do usuário

UI Automation Properties Overview