Disparar Eventos de um Provedor de Automação UI
Observação
Esta documentação destina.Os desenvolvedores do NET Framework que desejam usar o gerenciado UI Automation classes definidas na System.Windows.Automation namespace.As informações mais recentes sobre UI Automation, consulte API de automação do Windows: Automação da interface do usuário.
This topic contains example code that shows how to raise an event from a UI Automation provider.
Exemplo
In the following example, a UI Automation event is raised in the implementation of a custom button control. A implementação permite uma o cliente de automação da interface do usuário aplicativo para simular um botão de clique.
To avoid unnecessary processing, the example checks ClientsAreListening to see whether events should be raised.
''' <summary>
''' Responds to a button click, regardless of whether it was caused by a
''' mouse or keyboard click or by InvokePattern.Invoke.
''' </summary>
Private Sub OnCustomButtonClicked()
'' TODO Perform program actions invoked by the control.
'' Raise an event.
If AutomationInteropProvider.ClientsAreListening Then
Dim args As AutomationEventArgs = _
New AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent)
AutomationInteropProvider.RaiseAutomationEvent( _
InvokePatternIdentifiers.InvokedEvent, Me, args)
End If
End Sub
/// <summary>
/// Responds to a button click, regardless of whether it was caused by a mouse or
/// keyboard click or by InvokePattern.Invoke.
/// </summary>
private void OnCustomButtonClicked()
{
// TODO Perform program actions invoked by the control.
// Raise an event.
if (AutomationInteropProvider.ClientsAreListening)
{
AutomationEventArgs args = new AutomationEventArgs(InvokePatternIdentifiers.InvokedEvent);
AutomationInteropProvider.RaiseAutomationEvent(InvokePatternIdentifiers.InvokedEvent, this, args);
}
}