我在word里面插入一个ocx
这个ocx是用来显示图片的,用户可以从本地选择要显示的图片,所以我要把图片的数据保存在ocx里面
而word文件可以随便拷贝到不同的机子上面,所以不能配置INI或者数据库来保存图片信息,请问我可以用什么方法来解决这个问题呢

解决方案 »

  1.   

    Public Property Get Picture() As IPictureDisp
        Set Picture = UserControl.Picture
    End PropertyPublic Property Set Picture(ByVal vNewValue As IPictureDisp)
        Set UserControl.Picture = vNewValue
    End PropertyPrivate Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Set Picture = PropBag.ReadProperty("Pictrue", Nothing)
    End SubPrivate Sub UserControl_WriteProperties(PropBag As PropertyBag)
    PropBag.WriteProperty "Pictrue", UserControl.Picture, Nothing
    End Sub
      

  2.   

    你是要将图片保存到OCX里边么?
    如果你是在编译前将图片保存到OCX里是可能的,然而你要在编译后的使用过程中保存图片到OCX里的话?很对不起,这件事不太可能!
      

  3.   

    你可以把图片保存到word文件里。
      

  4.   

    我给你的就是一个简单的例子,建一个控件,把这段代码贴进去就行了,编译,打开word插入控件,设置属性,保存关闭,在从新打开
      

  5.   

    我使用的是word2003,插入就提示说接口不支持,出错了,不行
      

  6.   

    确实有这个问题,原因是
    PropBag.WriteProperty "Pictrue", UserControl.Picture, Nothing
    保存属性时并没有把整个对象完全保存进去,这里可能要自己处理一下,把IPictureDisp的二进制数据提取出来,再以这种方式保存,然后
    PropBag.ReadProperty("Pictrue", Nothing)
    时取出的也是二进制的数据,再恢复成IPictureDisp对象就可以了
    具体的代码,好像挺麻烦没找到现成的
      

  7.   

    闲着没事,又试了一下,发现加上On Error 就行了,还得加上 PropertyChanged "Pictrue"Public Property Get Picture() As IPictureDisp
        Set Picture = UserControl.Picture
        PropertyChanged "Pictrue"
    End PropertyPublic Property Set Picture(ByVal vNewValue As IPictureDisp)
        Set UserControl.Picture = vNewValue
    End PropertyPrivate Sub UserControl_ReadProperties(PropBag As PropertyBag)
    On Error Resume Next
    Set Picture = PropBag.ReadProperty("Pictrue", Nothing)
    End SubPrivate Sub UserControl_WriteProperties(PropBag As PropertyBag)
    On Error Resume Next
    PropBag.WriteProperty "Pictrue", UserControl.Picture, Nothing
    End Sub