Export (0) Print
Expand All

Automation.AddAutomationFocusChangedEventHandler Method

Registers a method that will handle focus-changed events.

Namespace:  System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public static void AddAutomationFocusChangedEventHandler(
	AutomationFocusChangedEventHandler eventHandler
)

Parameters

eventHandler
Type: System.Windows.Automation.AutomationFocusChangedEventHandler

The method to call when the event occurs.

Focus-changed events are system-wide; you cannot set a narrower scope.

eventHandler can be an instance of the method, or a reference to the method (AddressOf in Visual Basic).

The following example shows this method being used to add an event handler for focus changes.

AutomationFocusChangedEventHandler focusHandler = null;

/// <summary> 
/// Create an event handler and register it. 
/// </summary> 
public void SubscribeToFocusChange()
{
    focusHandler = new AutomationFocusChangedEventHandler(OnFocusChange);
    Automation.AddAutomationFocusChangedEventHandler(focusHandler);
}

/// <summary> 
/// Handle the event. 
/// </summary> 
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
private void OnFocusChange(object src, AutomationFocusChangedEventArgs e)
{
    // TODO Add event handling code. 
    // The arguments tell you which elements have lost and received focus.
}

/// <summary> 
/// Cancel subscription to the event. 
/// </summary> 
public void UnsubscribeFocusChange()
{
    if (focusHandler != null)
    {
        Automation.RemoveAutomationFocusChangedEventHandler(focusHandler);
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0

Community Additions

ADD
Show:
© 2015 Microsoft