我按照msdn上的控件编程一步一步做下来,可是添加了代码Caption = Extender.Name后,运行时就出现了错误!请问这是为什么,错误提示是不支持此对象!

解决方案 »

  1.   

    caption 是个属性名!这个已经定义了!
      

  2.   

    全部代码如下:
    Private Sub UserControl_Initialize()
    Debug.Print "Initialize"End SubPrivate Sub UserControl_InitProperties()
    '将 ShapeLabel 实例的名字
    '赋给 Caption 属性
    '作为它的初始值。
    Caption = Extender.NameDebug.Print "InitProperties"End SubPrivate Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Debug.Print "ReadProperties"
    Caption = PropBag.ReadProperty("Caption", _
    Extender.Name)
    End SubPrivate Sub UserControl_Resize()' 变换 Shape 控件的大小
    ' 以便填充 ShapeLabel 的可见表面。
    shpBack.Move 0, 0, ScaleWidth, ScaleHeight
    ' 使 Label 控件垂直居中,
    ' 并使它的宽度与 ShapeLabel 一致。
    lblCaption.Move 0, (ScaleHeight _
    - lblCaption.Height) / 2, ScaleWidthEnd SubPrivate Sub UserControl_Terminate()
    Debug.Print "Terminate"End SubPrivate Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Debug.Print "WriteProperties"
    PropBag.WriteProperty "Caption", Caption, _
    Extender.Name
    End SubPublic Property Get Caption() As String
    Caption = lblCaption.CaptionEnd PropertyPublic Property Let Caption(ByVal NewCaption As String)
    lblCaption.Caption = NewCaption
    PropertyChanged "Caption"End Property
      

  3.   

    Private Sub UserControl_Initialize()
    Debug.Print "Initialize"End SubPrivate Sub UserControl_InitProperties()
    '将 ShapeLabel 实例的名字
    '赋给 Caption 属性
    '作为它的初始值。
    Caption = Extender.NameDebug.Print "InitProperties"End SubPrivate Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Debug.Print "ReadProperties"
    Caption = PropBag.ReadProperty("Caption", _
    Extender.Name)
    End SubPrivate Sub UserControl_Resize()' 变换 Shape 控件的大小
    ' 以便填充 ShapeLabel 的可见表面。
    shpBack.Move 0, 0, ScaleWidth, ScaleHeight
    ' 使 Label 控件垂直居中,
    ' 并使它的宽度与 ShapeLabel 一致。
    lblCaption.Move 0, (ScaleHeight _
    - lblCaption.Height) / 2, ScaleWidthEnd SubPrivate Sub UserControl_Terminate()
    Debug.Print "Terminate"End SubPrivate Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Debug.Print "WriteProperties"
    PropBag.WriteProperty "Caption", Caption, _
    Extender.Name
    End SubPublic Property Get Caption() As String
    Caption = lblCaption.CaptionEnd PropertyPublic Property Let Caption(ByVal NewCaption As String)
    lblCaption.Caption = NewCaption
    PropertyChanged "Caption"End Property
      

  4.   

    按着你的代码我建了工程,在Usercontrol对象上加了一个Label控件,命名为lblCaption,加了一个Shape控件,命名为shpBack,然后将一个实例放至在窗体上,运行工程,没有错误啊。
    lblCaption.Caption是控件的名称啊。
      

  5.   

    我知道是什么问题了,是因为我每次运行程序时,程序就会自动打开ie,然后显示控件?为什么我不能直接运行我的那个testform呢?这是为什么呢?就是因为这个原因才出的问题!
      

  6.   

    把TestCtlDemo这个工程设为启动