首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

自制控件为什么不能存图片属性?解决方法

2012-02-02 
自制控件为什么不能存图片属性?自制一个控件,上面放两个image控件image1和image2用向导自建属性pic0和pic1

自制控件为什么不能存图片属性?
自制一个控件,上面放两个image控件image1和image2  

用向导自建属性pic0和pic1,分别映射到image1和image2的picture属性,自动生成如下代码,在设计的时候分别制定pic0和pic1的属性(bmp图片),可是一按F5运行图片却消失了,什么都没有,保存后再打开,图片也同样消失,自动生成的代码如下,高手快帮我看看哪里出问题了?

Option   Explicit

'注意!不要删除或修改下列被注释的行!
'MappingInfo=Image1,Image1,-1,Picture
Public   Property   Get   Pic0()   As   Picture
        Set   Pic0   =   Image1.Picture
End   Property

Public   Property   Set   Pic0(ByVal   New_Pic0   As   Picture)
        Set   Image1.Picture   =   New_Pic0
        PropertyChanged   "Pic0 "
End   Property

'注意!不要删除或修改下列被注释的行!
'MappingInfo=Image2,Image2,-1,Picture
Public   Property   Get   Pic1()   As   Picture
        Set   Pic1   =   Image2.Picture
End   Property

Public   Property   Set   Pic1(ByVal   New_Pic1   As   Picture)
        Set   Image2.Picture   =   New_Pic1
        PropertyChanged   "Pic1 "
End   Property

'从存贮器中加载属性值
Private   Sub   UserControl_ReadProperties(PropBag   As   PropertyBag)

        Set   Picture   =   PropBag.ReadProperty( "Pic0 ",   Nothing)
        Set   Picture   =   PropBag.ReadProperty( "Pic1 ",   Nothing)
End   Sub

'将属性值写到存储器
Private   Sub   UserControl_WriteProperties(PropBag   As   PropertyBag)

        Call   PropBag.WriteProperty( "Pic0 ",   Picture,   Nothing)
        Call   PropBag.WriteProperty( "Pic1 ",   Picture,   Nothing)
End   Sub




[解决办法]
修改下面代码:
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)

Set Image1.Picture = PropBag.ReadProperty( "Pic0 ", Nothing)
Set Image2.Picture = PropBag.ReadProperty( "Pic1 ", Nothing)
End Sub

'将属性值写到存储器
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)

Call PropBag.WriteProperty( "Pic0 ", Image1.Picture, Nothing)
Call PropBag.WriteProperty( "Pic1 ", Image2.Picture, Nothing)
End Sub

热点排行
Bad Request.