动态生成Command控件,如何动态修改Command控件的name属性,在线等~~~~~~~
动态生成Command控件,如何动态修改Command控件的name属性:
Private Sub Form_Click()
Dim Picture1, i
For i = 1 To 10
Form1.Controls.Add "VB.CommandButton ", "cmdOk " & Str$(i)
With Form1!cmdOk & Str$(i)
.Visible = True
.Width = 500
.Caption = i
End With
Next i
Print Form1.Width
End Sub
这样写不行,请大家指教,在问一下,With 中object是否能用变量.谢谢了
[解决办法]
Dim a
For Each a In Me '窗体集合
If TypeOf a Is CommandButton Then 'command控件
If a.Name = cmdOk & Str$(i) Then '选择的控件
a.Visible = True
a.Width = 500
a.Caption = i
End If
End If
Next
[解决办法]
Private Sub Command1_Click()
Dim i As Long
Dim cmd As CommandButton
For i = 1 To 10
Set cmd = Controls.Add( "VB.CommandButton ", "cmdOK " & CStr(i))
cmd.Caption = i
cmd.Visible = True
cmd.Move 500 * i, 1500, 300, 300
Next
End Sub