通过Extender,比如:Dim WithEvents btn As CommandButtonPrivate Sub btn_Click() '设置控件可视属性 UserControl.Extender.Visible = False End SubPrivate Sub UserControl_Initialize() UserControl.BackColor = vbRed Set btn = UserControl.Controls.Add("VB.CommandButton", "btn") btn.Visible = True End SubPrivate Sub UserControl_Terminate() UserControl.Controls.Remove "btn" End Sub
'设置控件可视属性
UserControl.Extender.Visible = False
End SubPrivate Sub UserControl_Initialize()
UserControl.BackColor = vbRed
Set btn = UserControl.Controls.Add("VB.CommandButton", "btn")
btn.Visible = True
End SubPrivate Sub UserControl_Terminate()
UserControl.Controls.Remove "btn"
End Sub