Private Sub Form_Load()
For i = 0 To 10
temp = "LB" & i
If i <> 0 Then
Set Lab(i) = Me.Controls.Add("VB.Label", temp, Me)
Else
Set Lab(0) = Label1(0)
End If
Lab(i).move 0,Lab(0).Height,Lab(0).Width,Lab(0).Height * i
Lab(i).Visible = True
Lab(i).Alignment = 2
Lab(i).BackStyle = 0
Lab(i).Caption = i
Next
End Sub
为什么这样生成的控件类,不能触发事件,高手指点
谢谢
For i = 0 To 10
temp = "LB" & i
If i <> 0 Then
Set Lab(i) = Me.Controls.Add("VB.Label", temp, Me)
Else
Set Lab(0) = Label1(0)
End If
Lab(i).move 0,Lab(0).Height,Lab(0).Width,Lab(0).Height * i
Lab(i).Visible = True
Lab(i).Alignment = 2
Lab(i).BackStyle = 0
Lab(i).Caption = i
Next
End Sub
为什么这样生成的控件类,不能触发事件,高手指点
谢谢
ByVal ObjParent As Object, ByVal ObjType As String, ByVal OBJName As String _
) As Object
On Error Resume Next
Set ObjectAdd = ObjParent.Controls.Add(ObjType, OBJName) Call Err.Clear
DoEvents
End FunctionPrivate Sub cmdButton_Click()
MsgBox "Success!!"
End SubPrivate Sub Command1_Click()
Set cmdButton = ObjectAdd(Me, "Vb.CommandButton", "Button")
With cmdButton
.Visible = True '显示出来
.Width = 1000
.Height = 1000
.Caption = "fuck u"
.Top = 100
.Left = 200
End WithEnd Sub
1,我测试了,这样的方法好像只能定义一个控件,我想用多个,用控件数组怎么办.
2,这样只能在触发 Command1_Click()事件后,才能用,能不能在窗口载入时就让它出现希望再给点建意谢谢
首先建立一个控件,把它的Index设置成0,后面再用load命令动态增加,卸载时用unload函数。