|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
Inscrever-se em eventos de automação da interface do usuário
Observação
|
|---|
|
|
// 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) { 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); } }
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); } }
Observação