1
在VB 6中如何使用变量而不是固定名称(如下面的LUH01)引用控件标签,该标签不允许循环。使用变量作为标签控件名称
Frm_Dispo_Prof_Grille.LUH01.BackColor = &HFF00&
在VB 6中如何使用变量而不是固定名称(如下面的LUH01)引用控件标签,该标签不允许循环。使用变量作为标签控件名称
Frm_Dispo_Prof_Grille.LUH01.BackColor = &HFF00&
您可以通过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
我想你想创建一个控制阵列
你可以通过创建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