假如一个form上有label1,label2,label3,....,labeln.
我写了一个通用的过程,用来对任意一个label的操作。假如我传入一个字符串参数"label2",就可以在该过程中操作这个label了。

解决方案 »

  1.   

    Sub aa(byref NewLable as Lable)
      NewLable.Caption="sub aa()"
    End Sub
      

  2.   

    例如:窗体上放一个LABEL1控件.Option ExplicitPrivate Sub Command1_Click()
           myfun "Label1"
    End SubSub myfun(ctrname As String)
        CallByName Form1, ctrname, VbLet, "asd"
    End Sub
      

  3.   


    Option ExplicitPublic WithEvents Ev_Label As VB.LabelPrivate Sub Command1_Click()
           MyFun "Label1"
    End SubSub MyFun(CtrName As String)
        Dim Ctr As Control
        For Each Ctr In Me.Controls
            If UCase$(Ctr.Name) = UCase$(CtrName) Then
               Set Ev_Label = Ctr
               Exit For
            End If
        Next
    End SubPrivate Sub Ev_Label_Click()
         MsgBox Ev_Label.Name
    End Sub
      

  4.   

    Private Sub Form_Click()
        aa Label1
        aa Text1
        aa Command1
    End SubPrivate Sub aa(bb As Object)
        bb.Left = 500
    End Sub
      

  5.   

    引用 Microsoft Script ConTrol 1.0如:Dim SCR As New ScriptControl
                 SCR.Language = "vbscript"
       
          
                 
                    SCR.AddObject "DG", JPFrm.DG1, True
                 
                
                     SCR.AddObject "Colorcom", ColorCom, True
                     SCR.AddCode "ColorCom.BackColor = DG." & TV1.SelectedItem.Key
                     Set SCR = Nothing