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

CustomControl.LostFocus 事件 (访问)CustomControl.LostFocus Event (Access)

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

指定的对象失去焦点时发生LostFocus事件。The LostFocus event occurs when the specified object loses the focus.

语法Syntax

表达式LostFocusexpression. LostFocus

表达式_一个表示CustomControl对象的变量。_expression A variable that represents a CustomControl object.

注解Remarks

若要在这些事件发生时运行宏或事件过程,请将OnLostFocus属性设置为宏的名称或 [事件过程]。To run a macro or event procedure when these events occur, set the OnLostFocus property to the name of the macro or to [Event Procedure].

当焦点为响应用户操作,例如,按下 TAB 键或单击该对象,或当您使用SetFocus方法在 Visual Basic 或 GoToRecord,移动,会发生此事件。This events occurs when the focus moves in response to a user action, such as pressing the TAB key or clicking the object, or when you use the SetFocus method in Visual Basic or the SelectObject, GoToRecord, GoToControl, or GoToPage action in a macro.

控件可以接收焦点,只有当其可见性,并启用属性设置为是。只有在它没有控件或所有可见控件都失效时,窗体可以接收焦点。如果窗体包含了任何可见的、 已启用的控件,该窗体的 GotFocus 事件不会发生。A control can receive the focus only if its Visible and Enabled properties are set to Yes. A form can receive the focus only if it has no controls or if all visible controls are disabled. If a form contains any visible, enabled controls, the GotFocus event for the form doesn't occur.

您可以指定在窗体或控件获得焦点的GotFocus事件发生时运行宏或事件过程时,会发生什么情况。例如,通过将GotFocus事件过程附加到窗体上每个控件,可以在文本框中显示简要的帮助或消息来指引用户通过您的应用程序。您还可以通过启用、 禁用或显示依赖于具有焦点的控件的控件提供可视化提示。You can specify what happens when a form or control receives the focus by running a macro or an event procedure when the GotFocus event occurs. For example, by attaching a GotFocus event procedure to each control on a form, you can guide the user through your application by displaying brief instructions or messages in a text box. You can also provide visual cues by enabling, disabling, or displaying controls that depend on the control with the focus.

请注意 若要自定义在按下 TAB 键时焦点在窗体控件间移动的顺序,设置 tab 键次序或指定控件的访问键。Note To customize the order in which the focus moves from control to control on a form when you press the TAB key, set the tab order or specify access keys for the controls.

LostFocus事件退出事件的不同之处在于LostFocus事件发生,每次一个控件失去焦点时。只能在从一个控件转移到同一窗体上另一个控件焦点之前,发生Exit事件。LostFocus事件发生后的退出事件。The LostFocus event differs from the Exit event in that the LostFocus event occurs every time a control loses the focus. The Exit event occurs only before a control loses the focus to another control on the same form. The LostFocus event occurs after the Exit event.

如果将焦点移到窗体上的控件,该控件不具有焦点,该窗体上,在窗体具有焦点的控件的ExitLostFocus事件发生之前的EnterGotFocus事件移动到的控件。If you move the focus to a control on a form, and that control doesn't have the focus on that form, the Exit and LostFocus events for the control that does have the focus on the form occur before the Enter and GotFocus events for the control you moved to.

如果使用鼠标将焦点从主窗体上的控件移动到该窗体的子窗体上的控件,将发生下列事件:If you use the mouse to move the focus from a control on a main form to a control on a subform of that form, the following events occur:

退出(对于主窗体上的控件)Exit (for the control on the main form)

ßß

LostFocus(对于主窗体上的控件)LostFocus (for the control on the main form)

ßß

输入(用于子窗体控件)Enter (for the subform control)

ßß

退出(适用于具有焦点的窗体控件)Exit (for the control on the subform that had the focus)

ßß

LostFocus(适用于具有焦点的窗体控件)LostFocus (for the control on the subform that had the focus)

ßß

输入(对于在焦点移到子窗体控件)Enter (for the control on the subform that the focus moved to)

ßß

GotFocus(对于在焦点移到子窗体控件)GotFocus (for the control on the subform that the focus moved to)

如果该控件移到子窗体上以前具有焦点时,其输入事件和其GotFocus事件都不会发生,但发生子窗体控件的输入事件。如果将焦点从子窗体上的控件移到主窗体上的控件时,子窗体上的控件的ExitLostFocus事件不会发生,刚子窗体控件的EnterGotFocus 的退出事件在主窗体上控件的事件。If the control you move to on the subform previously had the focus, neither its Enter event nor its GotFocus event occurs, but the Enter event for the subform control does occur. If you move the focus from a control on a subform to a control on the main form, the Exit and LostFocus events for the control on the subform don't occur, just the Exit event for the subform control and the Enter and GotFocus events for the control on the main form.

请注意 一般使用鼠标或如选项卡上的某个键以将焦点移到另一个控件。这会导致鼠标或键盘,还在本主题讨论的事件将发生的事件。Note You often use the mouse or a key such as TAB to move the focus to another control. This causes mouse or keyboard events to occur in addition to the events discussed in this topic.

在两个打开的窗体之间切换时,停用事件发生第一个窗体,以及激活事件发生的第二个窗体。如果窗体包含不可见,启用LostFocus事件发生之前停用事件中,第一个窗体控件,并激活事件后发生的第二个窗体, GotFocus事件。When you switch between two open forms, the Deactivate event occurs for the first form, and the Activate event occurs for the second form. If the forms contain no visible, enabled controls, the LostFocus event occurs for the first form before the Deactivate event, and the GotFocus event occurs for the second form after the Activate event.

示例Example

下面的示例在焦点移到选项按钮时,在标签中显示一条消息。The following example displays a message in a label when the focus moves to an option button.

若要试用该示例,请将下列事件过程添加到名为“联络人”的窗体中,并在该窗体中包含一个名为“OptionYes”的选项按钮和名为“LabelYes”的标签。To try the example, add the following event procedures to a form named Contacts that contains an option button named OptionYes and a label named LabelYes.

Private Sub OptionYes_GotFocus() 
 Me!LabelYes.Caption = "Option button 'Yes' has the focus." 
End Sub 

Private Sub OptionYes_LostFocus() 
 Me!LabelYes.Caption = "" ' Clear caption. 
End Sub

另请参阅See also

概念Concepts

CustomControl 对象CustomControl Object

© 2018 Microsoft