我做个控件,自定一个pic_main 属性 为 picture ,在usercontrol上面放了一个图片框,然后映射pic_main属性到 这个图片框 的picture 属性,设计时给该属性添加个图片,能正确显示,已运行就什么都没有了,况且该属性内容也丢失了,我不知道怎么回事,大家帮帮我。

解决方案 »

  1.   

    '属性变量:
    Dim m_Picture As Picture'End Property
    '注意!不要删除或修改下列被注释的行!
    'MemberInfo=11,0,0,0
    Public Property Get Picture() As Picture
        Set Picture = m_Picture
    End PropertyPublic Property Set Picture(ByVal New_Picture As Picture)
        Set m_Picture = New_Picture
        PropertyChanged "Picture"
    End Property'注意!不要删除或修改下列被注释的行!
    'MappingInfo=Picture1,Picture1,-1,Picture
    Public Property Get pic_main() As Picture
        Set pic_main = Picture1.Picture
    End PropertyPublic Property Set pic_main(ByVal New_pic_main As Picture)
        Set Picture1.Picture = New_pic_main
        PropertyChanged "pic_main"
    End Property'为用户控件初始化属性
    Private Sub UserControl_InitProperties()
        Set m_Picture = LoadPicture("")
    End Sub'从存贮器中加载属性值
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)    Set m_Picture = PropBag.ReadProperty("Picture", Nothing)
        Set Picture = PropBag.ReadProperty("pic_main", Nothing)
    End Sub'将属性值写到存储器
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)    Call PropBag.WriteProperty("Picture", m_Picture, Nothing)
        Call PropBag.WriteProperty("pic_main", Picture, Nothing)
    End Sub
      

  2.   

    '属性变量:
    Dim m_Picture As Picture???????????????
    自己不写这个行吗?人家不是自动生成了一对代码?
      

  3.   

    '缺省属性值:
    Const m_def_BackColor = 0
    Const m_def_ForeColor = 0
    Const m_def_Enabled = 0
    Const m_def_BackStyle = 0
    Const m_def_BorderStyle = 0
    '属性变量:
    Dim m_BackColor As Long
    Dim m_ForeColor As Long
    Dim m_Enabled As Boolean
    Dim m_Font As Font
    Dim m_BackStyle As Integer
    Dim m_BorderStyle As Integer
    '事件声明:
    Event Click()
    Event DblClick()
    Event KeyDown(KeyCode As Integer, Shift As Integer)
    Event KeyPress(KeyAscii As Integer)
    Event KeyUp(KeyCode As Integer, Shift As Integer)
    Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)'注意!不要删除或修改下列被注释的行!
    'MemberInfo=8,0,0,0
    Public Property Get BackColor() As Long
        BackColor = m_BackColor
    End PropertyPublic Property Let BackColor(ByVal New_BackColor As Long)
        m_BackColor = New_BackColor
        PropertyChanged "BackColor"
    End Property'注意!不要删除或修改下列被注释的行!
    'MemberInfo=8,0,0,0
    Public Property Get ForeColor() As Long
        ForeColor = m_ForeColor
    End PropertyPublic Property Let ForeColor(ByVal New_ForeColor As Long)
        m_ForeColor = New_ForeColor
        PropertyChanged "ForeColor"
    End Property'注意!不要删除或修改下列被注释的行!
    'MemberInfo=0,0,0,0
    Public Property Get Enabled() As Boolean
        Enabled = m_Enabled
    End PropertyPublic Property Let Enabled(ByVal New_Enabled As Boolean)
        m_Enabled = New_Enabled
        PropertyChanged "Enabled"
    End Property'注意!不要删除或修改下列被注释的行!
    'MemberInfo=6,0,0,0
    Public Property Get Font() As Font
        Set Font = m_Font
    End PropertyPublic Property Set Font(ByVal New_Font As Font)
        Set m_Font = New_Font
        PropertyChanged "Font"
    End Property'注意!不要删除或修改下列被注释的行!
    'MemberInfo=7,0,0,0
    Public Property Get BackStyle() As Integer
        BackStyle = m_BackStyle
    End PropertyPublic Property Let BackStyle(ByVal New_BackStyle As Integer)
        m_BackStyle = New_BackStyle
        PropertyChanged "BackStyle"
    End Property'注意!不要删除或修改下列被注释的行!
    'MemberInfo=7,0,0,0
    Public Property Get BorderStyle() As Integer
        BorderStyle = m_BorderStyle
    End PropertyPublic Property Let BorderStyle(ByVal New_BorderStyle As Integer)
        m_BorderStyle = New_BorderStyle
        PropertyChanged "BorderStyle"
    End Property'注意!不要删除或修改下列被注释的行!
    'MemberInfo=5
    Public Sub Refresh()
       Picture1.Picture = picsss
    End Sub'注意!不要删除或修改下列被注释的行!
    'MappingInfo=Picture1,Picture1,-1,Picture
    Public Property Get picsss() As Picture
        Set picsss = Picture1.Picture
    End PropertyPublic Property Set picsss(ByVal New_picsss As Picture)
        Set Picture1.Picture = New_picsss
        PropertyChanged "picsss"
    End PropertyPrivate Sub Picture1_Click()
       Picture1.Picture = picsss
    End Sub'为用户控件初始化属性
    Private Sub UserControl_InitProperties()
        m_BackColor = m_def_BackColor
        m_ForeColor = m_def_ForeColor
        m_Enabled = m_def_Enabled
        Set m_Font = Ambient.Font
        m_BackStyle = m_def_BackStyle
        m_BorderStyle = m_def_BorderStyle
        Set Picture = LoadPicture("")
    End Sub'从存贮器中加载属性值
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)    m_BackColor = PropBag.ReadProperty("BackColor", m_def_BackColor)
        m_ForeColor = PropBag.ReadProperty("ForeColor", m_def_ForeColor)
        m_Enabled = PropBag.ReadProperty("Enabled", m_def_Enabled)
        Set m_Font = PropBag.ReadProperty("Font", Ambient.Font)
        m_BackStyle = PropBag.ReadProperty("BackStyle", m_def_BackStyle)
        m_BorderStyle = PropBag.ReadProperty("BorderStyle", m_def_BorderStyle)
        Set Picture = PropBag.ReadProperty("picsss", Nothing)
    End Sub'将属性值写到存储器
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)    Call PropBag.WriteProperty("BackColor", m_BackColor, m_def_BackColor)
        Call PropBag.WriteProperty("ForeColor", m_ForeColor, m_def_ForeColor)
        Call PropBag.WriteProperty("Enabled", m_Enabled, m_def_Enabled)
        Call PropBag.WriteProperty("Font", m_Font, Ambient.Font)
        Call PropBag.WriteProperty("BackStyle", m_BackStyle, m_def_BackStyle)
        Call PropBag.WriteProperty("BorderStyle", m_BorderStyle, m_def_BorderStyle)
        Call PropBag.WriteProperty("picsss", Picture, Nothing)
    End Sub这是我的代码/可是怎么也出不来,谢谢了,大虾给看看..............................