Option Explicit
Private WithEvents NewPicture As PictureBox
'通过使用WithEvents关键字声明一个对象变量为新的命令按钮
Private Sub Command1_Click() '这个按钮用来添加新控件
If NewPicture Is Nothing Then
Set NewPicture = Controls.Add("VB.PictureBox","picture",Form1)
'增加新的按钮cmdNew
NewPicture.Move 500,500
'确定新增按钮cmdNew的位置
NewPicture.Visible = True
'显示该按钮
End If
End Sub
Private Sub Command2_Click() '这个按钮用来删除新控件If NewPicture Is Nothing Then Exit SubElse Controls.Remove NewPicture Set NewPicture = Nothing End IfEnd SubPrivate Sub NewButton_click() MsgBox "你点击了新建的PictureBox",vbDefaultButton1,"Click"End Sub
原文链接:https://www.f2er.com/vb/261393.html