如何判断窗体中是否存在某个控件?如:Line1(1)

解决方案 »

  1.   

    if not Line1(1) is nothing then
       '存在
    else
       '不存在
    end if
      

  2.   

    简单的方法,你可以建立一个函数,用出错来判断控件是否存在,如果不存在,能捕抓到错误正式的方法,是查找Controls集合    For Each ct In Controls
            If ct.Name = "Command1" Then
                MsgBox "存在"
            End If
        Next
      

  3.   

    不过后来发现,一楼的办法,仅仅是判断对象是否为nothing,而不是判断对象是否为控件如下面代码也会显示存在:
        Dim command1 As New Collection
        If Not command1 Is Nothing Then
            MsgBox "存在"
        End If