Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 2.32 KB

subscribe-to-ui-automation-events.md

File metadata and controls

41 lines (31 loc) · 2.32 KB
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
csharp
vb
UI Automation, subscribing to events
subscribing to UI Automation events
events, subscribing to
listening for events
how-to

Subscribe to UI Automation Events

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.

Example 1

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]

Example 2

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]

See also

  • 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