Automation.RemoveAutomationFocusChangedEventHandler Method (AutomationFocusChangedEventHandler)

 

Removes the specified focus-changed event handler.

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

public static void RemoveAutomationFocusChangedEventHandler(
	AutomationFocusChangedEventHandler eventHandler
)

Parameters

eventHandler
Type: System.Windows.Automation.AutomationFocusChangedEventHandler

A handler method that was passed to AddAutomationFocusChangedEventHandler

The following example code shows a focus-changed event handler being added and removed.

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);
    }
}

.NET Framework
Available since 3.0
Return to top
Show: