'举例: //在picture1上面添加一个commandbutton Private Sub Form_Load() Form1.Controls.Add "VB.CommandButton", "cmdOk", Picture1 With Form1!cmdOk .Visible = True .Width = 500 .Caption = "确认(&Y)" End With
Dim ctlNew As Control Dim ctlPrev As ControlPrivate Sub Command1_Click() If Not ctlPrev Is Nothing Then Controls.Remove ctlPrev End If Set ctlNew = Form1.Controls.Add("VB.Label", "lblNew") Set ctlPrev = ctlNew ctlNew.Left = 360 ctlNew.Top = 360 ctlNew.AutoSize = True ctlNew.Caption = "Label控件" ctlNew.Visible = True End Sub
Private Sub Form_Load()
Form1.Controls.Add "VB.CommandButton", "cmdOk", Picture1
With Form1!cmdOk
.Visible = True
.Width = 500
.Caption = "确认(&Y)"
End With
Dim ctlPrev As ControlPrivate Sub Command1_Click()
If Not ctlPrev Is Nothing Then
Controls.Remove ctlPrev
End If
Set ctlNew = Form1.Controls.Add("VB.Label", "lblNew")
Set ctlPrev = ctlNew
ctlNew.Left = 360
ctlNew.Top = 360
ctlNew.AutoSize = True
ctlNew.Caption = "Label控件"
ctlNew.Visible = True
End Sub
例:
Form1.Controls.Add "VB.CommandButton", "Command1"