Sub ControlProcessor(MyControl As Control)
   If TypeOf MyControl Is CommandButton Then
      Debug.Print "You passed in a " & TypeName(MyControl)
   ElseIf TypeOf MyControl Is CheckBox Then
      Debug.Print "You passed in a " & TypeName(MyControl)
   ElseIf TypeOf MyControl Is TextBox Then
      Debug.Print "You passed in a " & TypeName(MyControl)
   End If
End Sub

解决方案 »

  1.   

    我是不明白为什么
    If TypeOf NewItem Is Line Then
       MsgBox "Ok"
    End If
    判断不了

    TypeName(NewItem)="Line"可以CommandButton用那种方法都可以了,这两种在使用上有什么不同么?
      

  2.   

    可以的,不过LINE1为已加在窗体上的LINE控件:If TypeOf Line1 Is Line Then
       MsgBox "Ok"
    End If
    估计你的不能跟踪是因为你的控件对象是动态增加的吧,
    如果那样,一定要给动态对象赋值的(就像NEW)。
      

  3.   

    没有问题,这是我动态增加的LINE控件,VB6+WIN2000下通过了。Dim ln1 As Line
    Set ln1 = Controls.Add("vb.line", "ln1")
    With ln1
        .Visible = True
        .X1 = 500
        .X2 = 500
        .Y1 = 500
        .Y2 =500
    End With
    If TypeOf ln1 Is Line Then MsgBox ln1.Name
      

  4.   

    楼上的。
    Dim ln1 As Line
    Set ln1 = Controls.Add("vb.line", "ln1")
    With ln1
        .Visible = True
        .X1 = 500
        .X2 = 500
        .Y1 = 500
        .Y2 =500
    End With
    If TypeOf ln1 Is Line Then MsgBox ln1.Name
                     ……  随便写比如line123都是对的。
    ---------------------------------------------------------
    Montaque==Digitalboy==Houyongfeng==Monkey
      

  5.   

    TypeOf没有问题,你看一下你的代码。