InSelection 属性

expandtri全部显示

使用 InSelection 属性可以判定或指定“设计”视图中的窗体上的控件是否被选定。Boolean 型,可读/写。

expression.InSelection

expression     必需。返回“应用于”列表中的一个对象的表达式。

说明

InSelection 属性使用以下设置。

设置

说明

True

控件已选定。

False

控件未选定。

 

注释  只有在使用Visual Basic 时此属性才可用。

在控件被选定时,它的调整柄可见,所以可以调整大小。而且一次可选定多个控件。

示例

下列函数使用 InSelection 属性来确定 strControlName 控件是否被选定。

如果要试验下列代码,可将 IsControlSelected 函数代码粘贴到“罗斯文”示例数据库某一代码模块中的声明节,在“设计”视图中打开“客户”窗体,然后选取“公司名称”控件。在“调试”窗口中输入以下代码行:

? IsControlSelected (Forms!Customers, "CompanyName")

Function IsControlSelected(frm As Form, _

     strControlName As String) As Integer

    Dim intI As Integer, ctl As Control

    If frm.CurrentView <> 0 Then

        ' Form is not in Design view.

        Exit Function

    Else

        For intI = 0 To frm.Count - 1

            Set ctl = frm(intI)

            If ctl.InSelection = True Then

                ' Is desired control selected?

                If UCase(ctl.Name) = UCase(strControlName) Then

                    IsControlSelected = True

                    Exit Function

                End If

            Else

                IsControlSelected = False

            End If

        Next intI

    End If

End Function