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