2015-05-04 40 views

回答

1

您可以通过Controls Collection引用它:

Frm_Dispo_Prof_Grille.Controls("LUH01").BackColor = &HFF00& 

要小心,但是。如果您需要引用一个属性/方法不是标准/内置者之一,你必须控制转换为类型:

Dim lbl as Label 

Set lbl = Frm_Dispo_Prof_Grille.Controls("LUH01") 
lbl.BackColor = &HFF00 
0

我想你想创建一个控制阵列

你可以通过创建1所控制,其Index属性设置为0(而不是空的)

然后,您可以加载新的控件,并利用它们都在一个循环

例如以加载一些命令按钮并将它们放置在一个循环中:

'1 form with : 
' 1 command button: name=Command1 index=0 

'Number of command buttons to use in the loop 
Private Const NRBUTTONS As Integer = 5 

Option Explicit 

Private Sub Form_Load() 
    Dim intIndex As Integer 
    'change the caption of the default button 
    Command1(0).Caption = "Button 0" 
    For intIndex = 1 To NRBUTTONS - 1 
    'load an extra command button 
    Load Command1(intIndex) 
    'change the caption of the newly loaded button 
    Command1(intIndex).Caption = "Button " & CStr(intIndex) 
    'newly load command buttons are invisible by deafult 
    'make the new command button visible 
    Command1(intIndex).Visible = True 
    Next intIndex 
End Sub 

Private Sub Form_Resize() 
    'arrange all loaded command buttons via a loop 
    Dim intIndex As Integer 
    Dim sngWidth As Single 
    Dim sngHeight As Single 
    sngWidth = ScaleWidth 
    sngHeight = ScaleHeight/NRBUTTONS 
    For intIndex = 0 To NRBUTTONS - 1 
    Command1(intIndex).Move 0, intIndex * sngHeight, sngWidth, sngHeight 
    Next intIndex 
End Sub