Table of contents

ToggleButton.SetFocus 方法 (访问)ToggleButton.SetFocus Method (Access)

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

SetFocus 方法将焦点移到特定的窗体、活动窗体上特定的控件,或者活动数据表的特定字段上。The SetFocus method moves the focus to the specified form, the specified control on the active form, or the specified field on the active datasheet.


表达式SetFocusexpression. SetFocus

表达式_一个表示一个切换按钮对象的变量。_expression A variable that represents a ToggleButton object.

返回值Return Value



使用 SetFocus 方法可以让特定字段或控件获得焦点以便所有用户输入都针对这个对象。You can use the SetFocus method when you want a particular field or control to have the focus so that all user input is directed to this object.

为了读取控件的某些属性,需要确保该控件具有焦点。例如,在能读取文本框的 Text 属性之前,该文本框必须具有焦点。In order to read some of the properties of a control, you need to ensure that the control has the focus. For example, a text box must have the focus before you can read its Text property.

其他属性只有在控件没有焦点时才能设置。例如,当一个控件具有焦点时,不能将该控件的 VisibleEnabled 属性设置为 False (0)。Other properties can be set only when a control doesn't have the focus. For example, you can't set a control's Visible or Enabled properties to False (0) when that control has the focus.

此外可以使用SetFocus方法以根据特定的条件的窗体中导航。例如,如果用户选择不适用的一组问题为问卷窗体上的第一个问题,Visual Basic 代码可能自动跳过该集中的问题,然后将焦点移动到下一组中的第一个控件问题。You can also use the SetFocus method to navigate in a form according to certain conditions. For example, if the user selects Not applicable for the first of a set of questions on a form that's a questionnaire, your Visual Basic code might then automatically skip the questions in that set and move the focus to the first control in the next set of questions.

只能将焦点移到可见的控件或窗体上。窗体和窗体上的控件在窗体的 Load 事件已经结束后才可见。因此,如果在窗体的 Load 事件中使用 SetFocus 方法将焦点移到该窗体上,则必须先使用 Repaint 方法再使用 SetFocus 方法。You can move the focus only to a visible control or form. A form and controls on a form aren't visible until the form's Load event has finished. Therefore, if you use the SetFocus method in a form's Load event to move the focus to that form, you must use the Repaint method before the SetFocus method.

如果控件的 Enabled 属性设置为 False ,则不能将焦点移到该控件上。在将焦点移到该控件上之前,必须将其 Enabled 属性设置为 True (-1)。但如果该控件的 Locked 属性设置为 True ,则可以将焦点移到该控件上。You can't move the focus to a control if its Enabled property is set to False. You must set a control's Enabled property to True (-1) before you can move the focus to that control. You can, however, move the focus to a control if its Locked property is set to True.

如果窗体包含了 Enabled 属性设为 True 的控件,则不能将焦点移到窗体本身,而只能将焦点移到窗体控件上。在这种情况下,如果试图用 SetFocus 将焦点移到窗体上,则焦点将移到窗体中上次获得焦点的控件上。If a form contains controls for which the Enabled property is set to True, you can't move the focus to the form itself. You can only move the focus to controls on the form. In this case, if you try to use SetFocus to move the focus to a form, the focus is set to the control on the form that last received the focus.

使用 SetFocus 方法可以将焦点移到子窗体中,子窗体也是一种类型的控件。您也可以两次使用 SetFocus 方法将焦点移到子窗体上的某个控件上:首先将焦点移到子窗体,然后再移到子窗体上的控件上。You can use the SetFocus method to move the focus to a subform, which is a type of control. You can also move the focus to a control on a subform by using the SetFocus method twice, moving the focus first to the subform and then to the control on the subform.


下面的示例使用 SetFocus 方法将焦点移到 Employees 窗体上的 EmployeeID 文本框中:The following example uses the SetFocus method to move the focus to an EmployeeID text box on an Employees form:


另请参阅See also


切换按钮对象ToggleButton Object

© 2018 Microsoft