使用控件数组,把command1的index设置为0
Dim j As Long, lf As Long, tp As Long
Private Sub Command1_Click(Index As Integer)
j = j + 1
Load Command1(j)
lf = 10
tp = tp + 150
Command1(j).Left = lf
Command1(j).Top = tp
Command1(j).Visible = True
End Sub
Private Sub Command1_Click(Index As Integer)
Static i
i = i + 1
Load Command1(i)
Command1(i).Visible = True
Command1(i).Left = Command1(i).Left + Command1(i).Width * i
End Sub
添加一个commandbox控件 index属性为0 代码如上。
command1_click()
call command2_click
end sub
Me.Controls.Add 方法.
事实上, Me.Controls.Add 可以向 Form 内添加所有 VB 内置的任何控件和已经引用了的控件库中的控件, 而这些控件不必事先画入 Form 中.
Syntax:
Set obj = Me.Controls.Add(controlID, controlName)
例如 你第一个按钮的事件:
Private Sub Command1_Click()
Static i=2
Set hCmdNew = Me.Controls.Add("VB.CommandButton", "cmd" & i)
i = i + 1
With hCmdNew
' 这里设置新的按钮的属性.
End With
End Sub
例如添加一个 TextBox:
Set hNewEdit = Me.Controls.Add("VB.TextBox", "text1")
用户事件是不能控制代码的。你可以先隐藏一些按钮。然后单击让其出现