ocx编程小问题在线等待:设计时设定的属性值为何运行时消失.

yokel 2003-10-17 01:49:27
OCX中:
Dim strPicPath As String

Public Property Get PicPath() As String
PicPath = strPicPath
End Property

Public Property Let PicPath(strPath As String)
strPicPath = strPath
End Property

在使用此控件时,设计时指定PicPath属性为"c:\1.bmp",

运行时PicPath属性则为"",何理!
...全文
42 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yokel 2003-10-17
  • 打赏
  • 举报
回复
多谢,实不相瞒,初次写ocx.
试试先,好用立马给分.
lgxysl 2003-10-17
  • 打赏
  • 举报
回复
原因是你没有保存属性值.处理方法可参照"射天狼"先生的.
射天狼 2003-10-17
  • 打赏
  • 举报
回复
写错了,把这个
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
With PropBag
Text = .ReadProperty("PicPath", ini_strPicPath)
End With
End Sub

改成:

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
With PropBag
PicPath = .ReadProperty("PicPath", ini_strPicPath)
End With
End Sub
射天狼 2003-10-17
  • 打赏
  • 举报
回复
'属性初始值
Const ini_strPicPath As String

'属性设置值
Private strPicPath As String

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
With PropBag
Call .WriteProperty("PicPath", strPicPath, ini_strPicPath)
End With
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
With PropBag
Text = .ReadProperty("PicPath", ini_strPicPath)
End With
End Sub

Public Property Get PicPath() As String
PicPath = strPicPath
End Property

Public Property Let PicPath(strPath As String)
strPicPath = strPath
End Property

7,763

社区成员

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

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