Automation.AddAutomationFocusChangedEventHandler 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注册一个将处理 focus-changed 事件的方法。
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
的引用。
适用于
另请参阅
- RemoveAutomationFocusChangedEventHandler(AutomationFocusChangedEventHandler)
- AddAutomationEventHandler(AutomationEvent, AutomationElement, TreeScope, AutomationEventHandler)
- AddAutomationPropertyChangedEventHandler(AutomationElement, TreeScope, AutomationPropertyChangedEventHandler, AutomationProperty[])
- AddStructureChangedEventHandler(AutomationElement, TreeScope, StructureChangedEventHandler)
- 订阅 UI 自动化事件
- UI 自动化事件概述