RemoveAutomationEventHandler Method

Automation.RemoveAutomationEventHandler Method

Removes the specified UI Automation event handler.

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

public static void RemoveAutomationEventHandler (
	AutomationEvent eventId,
	AutomationElement element,
	AutomationEventHandler eventHandler
)
public static void RemoveAutomationEventHandler (
	AutomationEvent eventId, 
	AutomationElement element, 
	AutomationEventHandler eventHandler
)
public static function RemoveAutomationEventHandler (
	eventId : AutomationEvent, 
	element : AutomationElement, 
	eventHandler : AutomationEventHandler
)
Not applicable.

Parameters

eventId

An event identifier.

element

The UI Automation element on which to remove the event handler.

eventHandler

The handler method that was passed to AddAutomationEventHandler for the specified event identifier and UI Automation element.

The following example code shows an event handler being added and removed.

// Member variables.
AutomationElement ElementSubscribeButton;
AutomationEventHandler UIAeventHandler;

/// <summary>
/// Register an event handler for InvokedEvent on the specified element.
/// </summary>
/// <param name="elementButton">The automation element.</param>
public void SubscribeToInvoke(AutomationElement elementButton)
{
    if (elementButton != null)
    {
        Automation.AddAutomationEventHandler(InvokePattern.InvokedEvent,
             elementButton, TreeScope.Element,
             UIAeventHandler = new AutomationEventHandler(OnUIAutomationEvent));
        ElementSubscribeButton = elementButton;
    }
}

/// <summary>
/// AutomationEventHandler delegate.
/// </summary>
/// <param name="src">Object that raised the event.</param>
/// <param name="e">Event arguments.</param>
private void OnUIAutomationEvent(object src, AutomationEventArgs e)
{
    // Make sure the element still exists. Elements such as tooltips
    // can disappear before the event is processed.
    AutomationElement sourceElement;
    try
    {
        sourceElement = src as AutomationElement;
    }
    catch (ElementNotAvailableException ex)
    {
        return;
    }
    if (e.EventId == InvokePattern.InvokedEvent)
    {
        // TODO Add handling code.
    }
    else
    {
        // TODO Handle any other events that have been subscribed to.
    }
}

private void ShutdownUIA()
{
    if (UIAeventHandler != null)
    {
        Automation.RemoveAutomationEventHandler(InvokePattern.InvokedEvent,
            ElementSubscribeButton, UIAeventHandler);
    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2016 Microsoft