Table of contents
TOC
折叠目录
展开目录

CommandBarControl.SetFocus 方法 (办公室)CommandBarControl.SetFocus Method (Office)

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

将键盘的焦点移到指定 CommandBarControl。如果该控件被禁用或不可见,那么此方法将失败。Moves the keyboard focus to the specified CommandBarControl. If the control is disabled or isn't visible, this method will fail.

请注意 已通过 Microsoft Office 流畅的用户界面的新功能区组件取代某些 Microsoft Office 应用程序中的命令栏使用。有关更多信息,请搜索帮助关键字"功能区"。Note The use of CommandBars in some Microsoft Office applications has been superseded by the new ribbon component of the Microsoft Office Fluent user interface. For more information, search Help for the keyword "ribbon."

语法Syntax

表达式SetFocusexpression. SetFocus

表达式_一个表示命令栏控件对象的变量。_expression A variable that represents a CommandBarControl object.

注解Remarks

带有焦点的控件与其他控件的差别是十分细微的。在使用此方法后,会看到该控件处于三维突出显示的状态。按方向键将使焦点在工具栏中各控件间切换,就好像是按键盘控制键到达该控件一样。The focus on the control is subtle. After you use this method, you will notice a three dimensional highlight on the control. Pressing the arrow keys will navigate in the toolbars, as if you had arrived at the control by pressing only keyboard controls.

示例Example

本示例创建一个名为"Custom"的命令栏,并向其添加一个组合框控件和一个按钮控件。该示例然后使用SetFocus方法将焦点设置到该组合框控件。This example creates a command bar named "Custom" and adds a ComboBox control and a Button control to it. The example then uses the SetFocus method to set the focus to the ComboBox control.

Set focusBar = CommandBars.Add(Name:="Custom") 
With CommandBars("Custom") 
    .Visible = True  
    .Position = msoBarTop 
End With 

Set testComboBox = CommandBars("Custom").Controls _ 
    .Add(Type:=msoControlComboBox, ID:=1) 
With testComboBox 
    .AddItem "First Item", 1 
    .AddItem "Second Item", 2 
End With 
Set testButton = CommandBars("Custom").Controls _ 
    .Add(Type:=msoControlButton) 
testButton.FaceId = 17 
' Set the focus to the combo box. 
testComboBox.SetFocus

另请参阅See also

概念Concepts

命令栏控件对象CommandBarControl Object

其他资源Other resources

命令栏控件对象成员CommandBarControl Object Members

© 2018 Microsoft