UI Automation Events for Clients
Actualización: noviembre 2007
This topic describes how Automatización de la interfaz de usuario de Microsoft events are used by UI Automation clients.
Automatización de la interfaz de usuario allows clients to subscribe to events of interest. This capability improves performance by eliminating the need to continually poll all the interfaz de usuario 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 Automatización de la interfaz de usuario elements in the tree, or on just one element and its descendants.
Nota: |
---|
Do not assume that all possible events are raised by a Automatización de la interfaz de usuario de Microsoft provider. For example, not all property changes cause events to be raised by the standard proxy providers for formularios Windows Forms and Win32 controls. |
For a broader view of Automatización de la interfaz de usuario events, see UI Automation Events Overview.
Este tema contiene las secciones siguientes.
- Subscribing to Events
- Temas 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 |
---|---|---|---|
Focus change |
|||
Property change |
|||
Structure change |
|||
All other events, identified by an AutomationEvent |
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.
Nota: |
---|
To process window-closed events, cast the argument type that is passed to the event handler as WindowClosedEventArgs. Because the Automatización de la interfaz de usuario de Microsoft element for the window is no longer valid, you cannot use the sender parameter to retrieve information; use GetRuntimeId instead. |
Precaución: |
---|
If your application might receive events from its own interfaz de usuario, do not use your application's interfaz de usuario thread to subscribe to events, or to unsubscribe. Doing so might lead to unpredictable behavior. For more information, see UI Automation Threading Issues. |
On shutdown, or when Automatización de la interfaz de usuario events are no longer of interest to the application, UI Automation clients should call one of the following methods.
Method |
Description |
---|---|
Unregisters an event handler that was registered by using AddAutomationEventHandler. |
|
Unregisters an event handler that was registered by using AddAutomationFocusChangedEventHandler. |
|
Unregisters an event handler that was registered by using AddAutomationPropertyChangedEventHandler. |
|
Unregisters all registered event handlers. |
For example code, see Subscribe to UI Automation Events.
Vea también
Tareas
Subscribe to UI Automation Events