主题:[讨论]【求助】动态创建的对象怎么相应事件
我写了一个动态创建对象的函数
Function addControl(ByVal pName As String, ByVal pType As String, ByVal pCaption As String, ByVal x As Long, ByVal y As Long)
Dim bt
Set bt = Me.Controls.Add(pType, pName)
Set bt.Container = Me
If pType = "VB.TextBox" Then
bt.Text = pCaption
ElseIf pType = "VB.CommandButton" Then
bt.Caption = pCaption
End If
bt.Top = y
bt.Left = x
bt.Visible = True
End Function
在程序中调用
Call addControl("Text1", "VB.CommandButton", "Hello World", 300, 300)
可以成功的添加一个按钮
但是怎么为这个按钮添加事件呢?
【注明:我这个不是用控件数组来动态创建,所以所有回答动态控件数组的同志们请绕道】
Function addControl(ByVal pName As String, ByVal pType As String, ByVal pCaption As String, ByVal x As Long, ByVal y As Long)
Dim bt
Set bt = Me.Controls.Add(pType, pName)
Set bt.Container = Me
If pType = "VB.TextBox" Then
bt.Text = pCaption
ElseIf pType = "VB.CommandButton" Then
bt.Caption = pCaption
End If
bt.Top = y
bt.Left = x
bt.Visible = True
End Function
在程序中调用
Call addControl("Text1", "VB.CommandButton", "Hello World", 300, 300)
可以成功的添加一个按钮
但是怎么为这个按钮添加事件呢?
【注明:我这个不是用控件数组来动态创建,所以所有回答动态控件数组的同志们请绕道】