高分求助:如何在vb中动态添加控件,并动态生成被添加控件的事件???
例如:
Set btnObj = Controls.Add("VB.CommandButton", "btnObj")
With btnObj
' .Index = 1
.Visible = True
.Width = 2000
.Caption = "Hello"
.Top = 1000
.Left = 1000
End With
动态添加一个CommandButton控件以后,需要:
Private Sub btnObj_Click()
MsgBox "这是动态添加的按钮。"
MsgBox "remove self"
Controls.Remove btnObj
Set NewButton = Nothing
End Sub
这个类似的事件(生成控件以后再生效的)。不能用:
Private WithEvents btnObj as CommandButton
因为事先并不知道要动态生成多少个控件!
给个思路也行~~~~~~~~```