同上.
例如是textbox或者picturebox

解决方案 »

  1.   

    利用 If TypeOf 可以判断传入过程的控件是否为一文本框。
    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
      

  2.   

    dim ctrl as control
    for each ctrl in form.controls
    if typeof ctrl is commandbutton then
    msgbox "the ctrl is commandbutton"
    endif
      

  3.   

    Private Sub Command2_Click()
    For Each ctl In Form1.Controls
        MsgBox TypeName(ctl)
    Next
    End Sub