title | description | ms.date | dev_langs | helpviewer_keywords | ms.topic | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Subscribe to UI Automation Events |
See how to subscribe to events raised by UI Automation providers. The example code registers an event handler for the event raised when a control is invoked. |
03/30/2017 |
|
|
how-to |
Note
This documentation is intended for .NET Framework developers who want to use the managed UI Automation classes defined in the xref:System.Windows.Automation namespace. For the latest information about UI Automation, see Windows Automation API: UI Automation.
This topic shows how to subscribe to events raised by UI Automation providers.
The following example code registers an event handler for the event that is raised when a control such as a button is invoked, and removes it when the application form closes. The event is identified by an xref:System.Windows.Automation.AutomationEvent passed as a parameter to xref:System.Windows.Automation.Automation.AddAutomationEventHandler%2A.
[!code-csharpUIAClient_snip#101] [!code-vbUIAClient_snip#101]
The following example shows how to use Microsoft UI Automation to subscribe to an event that is raised when the focus changes. The event handler is unregistered in a method that could be called on application shutdown, or when notification of UI events is no longer required.
[!code-csharpUIAClient_snip#102] [!code-vbUIAClient_snip#102]
- xref:System.Windows.Automation.Automation.AddAutomationEventHandler%2A
- xref:System.Windows.Automation.Automation.RemoveAllEventHandlers%2A
- xref:System.Windows.Automation.Automation.RemoveAutomationEventHandler%2A
- UI Automation Events Overview