添加一个按钮
设置index属性为0
Private Sub Command1_Click(Index As Integer)
If Index = 0 Then
Load Command1(1) '添加按钮
Command1(1).Left = 0 '调整位置
Command1(1).Top = 0
Command1(1).Visible = True '设置可见
Else
Unload Command1(1) '卸载按钮
End If
End Sub
Dim WithEvents MyButten As CommandButton
Private Sub Command1_Click()
Set MyButten = Controls.Add("VB.CommandButton", "Name1")
MyButten.Move 200, 200, 1000, 1000
MyButten.Caption = "动态添加"
MyButten.Visible = True
End Sub
Private Sub MyButten_Click()
Controls.Remove MyButten
Set MyButten = Nothing
End Sub
删除就是生成后然后把Visible参数改成False就可以消失了
可以实现。