如何给自制控件添加一个这样的事件,当控件的某个属性为TRUE时这个方法就开始自动的运行

解决方案 »

  1.   

    '以 autoredraw 为示例'缺省属性值:
    Const m_def_AutoRedraw = 0
    '属性变量:
    Dim m_AutoRedraw As Boolean
    '注意!不要删除或修改下列被注释的行!
    'MemberInfo=0,0,0,0
    Public Property Get AutoRedraw() As Boolean
        AutoRedraw = m_AutoRedraw
    End PropertyPublic Property Let AutoRedraw(ByVal New_AutoRedraw As Boolean)
        m_AutoRedraw = New_AutoRedraw
        
        '************************************
        If m_AutoRedraw = True Then  '加上判断语句
           
           Call 自定义方法
        End If
        '**********************************
        
        PropertyChanged "AutoRedraw"
    End Property'为用户控件初始化属性
    Private Sub UserControl_InitProperties()
        m_AutoRedraw = m_def_AutoRedraw
    End Sub'从存贮器中加载属性值
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)    m_AutoRedraw = PropBag.ReadProperty("AutoRedraw", m_def_AutoRedraw)
    End Sub'将属性值写到存储器
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)    Call PropBag.WriteProperty("AutoRedraw", m_AutoRedraw, m_def_AutoRedraw)
    End Sub
    '**************************
    Private Function 自定义方法()
       
    End Function
      

  2.   

    '以 autoredraw 为示例
    '以下为产生事件示例
    '缺省属性值:
    Const m_def_AutoRedraw = 0
    '属性变量:
    Dim m_AutoRedraw As Boolean'**********声明一个事件
    Event 自定义事件()
    '注意!不要删除或修改下列被注释的行!
    'MemberInfo=0,0,0,0
    Public Property Get AutoRedraw() As Boolean
        AutoRedraw = m_AutoRedraw
    End PropertyPublic Property Let AutoRedraw(ByVal New_AutoRedraw As Boolean)
        m_AutoRedraw = New_AutoRedraw
        
        '************************************
        If m_AutoRedraw = True Then  '加上判断语句
        
           RaiseEvent 自定义事件   '加上此句,当进行设置的时候,将会产生事件
           
           Call 自定义方法
        End If
        '**********************************
        
        PropertyChanged "AutoRedraw"
    End Property'为用户控件初始化属性
    Private Sub UserControl_InitProperties()
        m_AutoRedraw = m_def_AutoRedraw
    End Sub'从存贮器中加载属性值
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)    m_AutoRedraw = PropBag.ReadProperty("AutoRedraw", m_def_AutoRedraw)
    End Sub'将属性值写到存储器
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)    Call PropBag.WriteProperty("AutoRedraw", m_AutoRedraw, m_def_AutoRedraw)
    End Sub
    '**************************
    Private Function 自定义方法()
       
    End Function