Dim WithEvents ctlCommand As VB.CommandButtonPrivate Sub ctlCommand_Click() MsgBox "click" End SubPrivate Sub Form_Load() Set ctlCommand = Controls.Add("VB.CommandButton", "ctlCommand1", Me) '设置CommandButton的位置和尺寸ctlCommand.Top = 400 + 200 ctlCommand.Left = 20'设置CommandButton的标题 ctlCommand.Caption = "点击" '使CommandButton可见 ctlCommand.Visible = TrueEnd Sub
'先有form1上加一个text1 (0)Private Sub Form_Load() For i = 1 To 10 Load Text1(i) Text1(i).Top = 400 * i + 200 Text1(i).Left = 20 Text1(i).Visible = True Next End Sub
MsgBox "click"
End SubPrivate Sub Form_Load()
Set ctlCommand = Controls.Add("VB.CommandButton", "ctlCommand1", Me)
'设置CommandButton的位置和尺寸ctlCommand.Top = 400 + 200
ctlCommand.Left = 20'设置CommandButton的标题
ctlCommand.Caption = "点击"
'使CommandButton可见
ctlCommand.Visible = TrueEnd Sub
For i = 1 To 10
Load Text1(i)
Text1(i).Top = 400 * i + 200
Text1(i).Left = 20
Text1(i).Visible = True
Next
End Sub