Private WithEvents NewButton As PictureBox
Private WithEvents NewLabel As Label
'增加控件
Private Sub Command1_Click()
Static i As Long
' If NewButton Is Nothing Then
'增加新的按钮cmdNew
Set NewButton = Controls.Add("VB.picturebox", "cmdNew" & CStr(i), Me)
' set NewButton.Index
'确定新增按钮cmdNew的位置
NewButton.Move 1240 + i * 300, Command1.Top, 200, 4000
' NewButton.Caption = "新增的按钮"
NewButton.Visible = True
' MsgBox NewButton.Name
' End If
i = i + 1
End Sub
Private Sub Command2_Click()
If NewLabel Is Nothing Then
'增加新的按钮cmdNew
Set NewLabel = Controls.Add("VB.Label", "lblNew", NewButton)
'确定新增按钮cmdNew的位置
NewLabel.Left = 10
NewLabel.Top = 20
NewLabel.Caption = "121"
NewLabel.BorderStyle = 1
NewLabel.Visible = True
End If
End Sub
Private Sub Command3_Click()
Controls.Remove NewButton
Set NewButton = Nothing
Set NewLabel = Nothing