全部显示

ActiveControl 属性

       

使用 ActiveControl 属性可以和 Screen 对象一起来识别或引用获得焦点控件Control 对象,只读。

expression.ActiveControl

expression   必需。返回“Applies To”列表中的一个对象的表达式。

设置

此属性设置中包含对在运行时获得焦点的 Control 对象的引用。

该属性仅在使用Visual Basic 时才可用,并且在所有视图中具有只读属性。

说明

可以使用 ActiveControl 属性来引用在运行时与其属性或方法之一共同获得焦点的控件。以下示例将获得焦点的控件名称指定给 strControlName 变量:

Dim ctlCurrentControl As Control
Dim strControlName As String
Set ctlCurrentControl = Screen.ActiveControl
strControlName = ctlCurrentControl.Name

如果在使用 ActiveControl 属性时没有控件获得焦点,或所有窗体中的活动控件都是隐藏或失效的,则会产生错误。

示例

下面的示例将活动控件指定给 ctlCurrentControl 变量,然后根据不同的控件 Name 属性值,采取不同的操作。

Dim ctlCurrentControl As Control

Set ctlCurrentControl = Screen.ActiveControl
If ctlCurrentControl.Name = "txtCustomerID" Then
    .
    . ' Do something here.
    .
ElseIf ctlCurrentControl.Name = "btnCustomerDetails" Then
    .
    . ' Do something here.
    .
End If