Partager via


Automation.AddAutomationFocusChangedEventHandler Méthode

Définition

Enregistre une méthode qui gérera des événements de modification de focus.

public:
 static void AddAutomationFocusChangedEventHandler(System::Windows::Automation::AutomationFocusChangedEventHandler ^ eventHandler);
public static void AddAutomationFocusChangedEventHandler (System.Windows.Automation.AutomationFocusChangedEventHandler eventHandler);
static member AddAutomationFocusChangedEventHandler : System.Windows.Automation.AutomationFocusChangedEventHandler -> unit
Public Shared Sub AddAutomationFocusChangedEventHandler (eventHandler As AutomationFocusChangedEventHandler)

Paramètres

eventHandler
AutomationFocusChangedEventHandler

Méthode à appeler lorsque l'événement se produit.

Exemples

L’exemple suivant montre cette méthode utilisée pour ajouter un gestionnaire d’événements pour les modifications de focus.

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);
    }
}
Private focusHandler As AutomationFocusChangedEventHandler = Nothing


''' <summary>
''' Create an event handler and register it.
''' </summary>
Public Sub SubscribeToFocusChange()
    focusHandler = New AutomationFocusChangedEventHandler(AddressOf OnFocusChange)
    Automation.AddAutomationFocusChangedEventHandler(focusHandler)

End Sub


''' <summary>
''' Handle the event.
''' </summary>
''' <param name="src">Object that raised the event.</param>
''' <param name="e">Event arguments.</param>
Private Sub OnFocusChange(ByVal src As Object, ByVal e As AutomationFocusChangedEventArgs)

End Sub

' TODO Add event handling code.
' The arguments tell you which elements have lost and received focus.

''' <summary>
''' Cancel subscription to the event.
''' </summary>
Public Sub UnsubscribeFocusChange()
    If (focusHandler IsNot Nothing) Then
        Automation.RemoveAutomationFocusChangedEventHandler(focusHandler)
    End If

End Sub

Remarques

Les événements modifiés au focus sont à l’échelle du système ; vous ne pouvez pas définir une étendue plus étroite.

eventHandlerpeut être une instance de la méthode ou une référence à la méthode (AddressOfdans Visual Basic).

S’applique à

Voir aussi