共用方式為


Automation.AddAutomationFocusChangedEventHandler 方法

定義

註冊要處理焦點變更事件的方法。

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)

參數

eventHandler
AutomationFocusChangedEventHandler

事件發生時要呼叫的方法。

範例

下列範例顯示這個方法用於新增焦點變更的事件處理常式。

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

備註

焦點變更事件全系統;您無法設定較窄的範圍。

eventHandler可以是 方法的實例,或是Visual Basic) 中方法 (AddressOf 的參考。

適用於

另請參閱