Vb6 使用变量作为标签控件名称
在VB6中,如何使用变量来引用控件标签,而不是使用固定名称,例如不允许循环的LUH01(如下所示)Vb6 使用变量作为标签控件名称,vb6,Vb6,在VB6中,如何使用变量来引用控件标签,而不是使用固定名称,例如不允许循环的LUH01(如下所示) Frm_Dispo_Prof_Grille.LUH01.BackColor = &HFF00& 您可以通过以下网址查阅: 但是要小心。如果需要引用的属性/方法不是标准/内置属性/方法之一,则必须将控件强制转换为以下类型: Dim lbl as Label Set lbl = Frm_Dispo_Prof_Grille.Controls("LUH01") lbl.BackCol
Frm_Dispo_Prof_Grille.LUH01.BackColor = &HFF00&
您可以通过以下网址查阅: 但是要小心。如果需要引用的属性/方法不是标准/内置属性/方法之一,则必须将控件强制转换为以下类型:
Dim lbl as Label
Set lbl = Frm_Dispo_Prof_Grille.Controls("LUH01")
lbl.BackColor = &HFF00
我认为您需要创建一个控制数组 可以通过创建1控件并将其索引属性设置为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
'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