我的自制控件中有两个image控件,我用接口向导将两个字定义属性p1、p2绑定到两个image的picture属性上,在设计时,可以在属性窗口中设置p1、p2,也能看到效果,但是一运行,图片就不见了。请问如何解决?当然,不在属性窗口中设置,在代码中写p1=loadpicture(xx)当然可以,但是觉得不够友好。
还有,我想制作一个属性用于保存控件对象,应该如何写接口?
请教!

解决方案 »

  1.   

    你用控件向导生成的代码应该是这样的:
    '注意!不要删除或修改下列被注释的行!
    'MappingInfo=Image1,Image1,-1,Picture
    Public Property Get P1() As Picture
        Set P1 = Image1.Picture
    End PropertyPublic Property Set P1(ByVal New_P1 As Picture)
        Set Image1.Picture = New_P1
        PropertyChanged "P1"
    End Property'注意!不要删除或修改下列被注释的行!
    'MappingInfo=Image2,Image2,-1,Picture
    Public Property Get P2() As Picture
        Set P2 = Image2.Picture
    End PropertyPublic Property Set P2(ByVal New_P2 As Picture)
        Set Image2.Picture = New_P2
        PropertyChanged "P2"
    End Property'从存贮器中加载属性值
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)    Set Picture = PropBag.ReadProperty("P1", Nothing)
        Set Picture = PropBag.ReadProperty("P2", Nothing)
    End Sub'将属性值写到存储器
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)    Call PropBag.WriteProperty("P1", Picture, Nothing)
        Call PropBag.WriteProperty("P2", Picture, Nothing)
    End Sub应该修改上面的代码如下:
    '注意!不要删除或修改下列被注释的行!
    'MappingInfo=Image2,Image2,-1,Picture
    Public Property Get P2() As Picture
        Set P2 = Image2.Picture
    End PropertyPublic Property Set P2(ByVal New_P2 As Picture)
        Set Image2.Picture = New_P2
        PropertyChanged "P2"
    End Property'从存贮器中加载属性值
    Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
        ''***注意下面两句已改
        Set Image1.Picture = PropBag.ReadProperty("P1", Nothing)
        Set Image2.Picture = PropBag.ReadProperty("P2", Nothing)
    End Sub'将属性值写到存储器
    Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
        ''***注意下面两句已改
        Call PropBag.WriteProperty("P1", Image1.Picture, Nothing)
        Call PropBag.WriteProperty("P2", Image2.Picture, Nothing)
    End Sub
      

  2.   

    比如窗体上有一控件叫obj,我自制控件有一个属性叫o,如何用o保存obj的句柄?就是说,赋值以后,可以在自制控件内部用o调用obj的属性和方法。