谁能用白话解释一下withevent,它是一个过程吗

解决方案 »

  1.   

    在VB工程里面,新建一个类模块Option ExplicitPublic Event PropertyChanged(ByVal PropName As String, ByVal OldValue As String, ByVal NewValue As String)Private m_Text As StringPublic Property Get Text() As String
        Text = m_Text
    End PropertyPublic Property Let Text(ByVal nText As String)
        If nText <> m_Text Then
            Dim OldText As String
            OldText = m_Text
            m_Text = nText
            RaiseEvent PropertyChanged("Text", OldText, nText)
        End If
    End Property然后在Form1.frm里面这么做Option ExplicitPublic WithEvents oTest As TestClassPrivate Sub Form_Load()
        Set oTest = New TestClass
        oTest.Text = "123"
        oTest.Text = "456"
    End SubPrivate Sub oTest_PropertyChanged(ByVal PropName As String, ByVal OldValue As String, ByVal NewValue As String)
        MsgBox "oTest 的属性 " & PropName & " 从 “" & OldValue & "” 变成 “" & NewValue & "” 了!"
    End Sub
      

  2.   

    当你在 Form1里面用 Public WithEvents oTest As TestClass 定义了这么一个对象以后在代码窗口里面,上面的对象选择下拉框里就可以看到oTest这个东东了
    跟你在窗体上拖的那些控件一样
      

  3.   

    十分感谢eglic,关键是人品,分不分的有啥重要