相当于动态添加控件 Option ExplicitPrivate WithEvents NewButton As CommandButton Private Sub Command1_Click() If NewButton Is Nothing Then Set NewButton = Controls.Add("VB.CommandButton", "cmdNew", Frame1) 'NewButton.Move Command1.Left Command1.Width + 240,Command1.Top NewButton.Move 20, 20 NewButton.Caption = "New Button" NewButton.Visible = True End If End Sub Private Sub Command2_Click() Form1.Controls.Remove NewButton End SubPrivate Sub NewButton_Click() MsgBox "New button clicked" End Sub
Option ExplicitPrivate WithEvents NewButton As CommandButton
Private Sub Command1_Click()
If NewButton Is Nothing Then
Set NewButton = Controls.Add("VB.CommandButton", "cmdNew", Frame1)
'NewButton.Move Command1.Left Command1.Width + 240,Command1.Top
NewButton.Move 20, 20
NewButton.Caption = "New Button"
NewButton.Visible = True
End If
End Sub
Private Sub Command2_Click()
Form1.Controls.Remove NewButton
End SubPrivate Sub NewButton_Click()
MsgBox "New button clicked"
End Sub
[email protected]
谢谢
[email protected]