自制控件为什么不能存图片属性?

stlyl 2007-01-02 09:29:47
自制一个控件,上面放两个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




...全文
171 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
韧恒 2007-01-04
  • 打赏
  • 举报
回复
控件向导只是一个辅助工具,它的确可以省去我们很多编写重复代码的时间,但事实上还有很多不足,很多时候我们需要手工去改写它生成的代码。不要太依赖它。
韧恒 2007-01-03
  • 打赏
  • 举报
回复
修改下面代码:
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
韧恒 2007-01-03
  • 打赏
  • 举报
回复
修改下面代码:
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
tmd007 2007-01-03
  • 打赏
  • 举报
回复
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", Pic0, Nothing)
Call PropBag.WriteProperty("Pic1", Pic1, Nothing)
End Sub
stlyl 2007-01-03
  • 打赏
  • 举报
回复
我都将属性映射到image1和image2了, 为什么不会自动生成正确的代码呢?
韧恒 2007-01-03
  • 打赏
  • 举报
回复
改写下面代码:

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

1,451

社区成员

发帖
与我相关
我的任务
社区描述
VB 控件
社区管理员
  • 控件
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧