在类中为Form动态增加的控件不响应事件,如何解决

在类中为Form动态增加的控件不响应事件,怎么解决?
在类中对Form作一些控件上的增减,并需要增加的控件都响应事件

VB code

''Class1.cls

''定义
Private frm As Form
Private WithEvents lblAdvance As Label

Public Sub InitData()
    Set frm = Form1

    Set lblAdvance = frm.Controls.Add("VB.Label", "lblAdvance")
    lblAdvance.Move 4590, 1950, 780, 195
    lblAdvance.BackStyle = 0 'Transport
    lblAdvance.ForeColor = vbBlue
    lblAdvance.FontUnderline = True
    lblAdvance.MousePointer = vbCustom
    lblAdvance.MouseIcon = LoadResPicture(101, vbResCursor) ''光标也没发生变化哦 
    lblAdvance.Caption = "高级模式"
    lblAdvance.Visible = True
End Sub

''Label 单击事件
Private Sub lblAdvance_Click()
    MsgBox "Click"
End Sub




这样动产生的事件,鼠标点击Label时没有反应,而且光标也没有变化,这个要怎么解决?

------解决方案--------------------
你在哪里创建的 Class1 实例?
肯定过早地释放了该实例,应该和 Form1 的生命周期同步。
VB code
'Form1
Option Explicit

Private c1 As Project1.Class1

Private Sub Form_Load()
    Set c1 = New Class1
    c1.InitData
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Set c1 = Nothing
End Sub

------解决方案--------------------
探讨

这段代码放到 Form 里面执行是完全正常的,放到类里面才会不行,这里的区别在哪里呢?

------解决方案--------------------
但是如果你放在了全局的位置,就一定要像我那样,在UnLoad事件里将A设置为Nothing来清除对象
------解决方案--------------------
你用了多个 Form1 实例?
加入下面两句调试,看输出
VB code
'Form1
Private Sub Form_Load()
    Debug.Print Now, "Form_Load()", Hex(Me.hWnd)
    '''
End Sub

------解决方案--------------------
要控件响应事件,必须制定他的容器:

Set lblAdvance = frm.Controls.Add("VB.Label", "lblAdvance")
改为
Set lblAdvance = frm.Controls.Add("VB.Label", "lblAdvance",frm)

这样就响应时间了。