在vb6中添加属性到用户控件

Add property to user control in vb6

我在网上找到了这样的代码,但它似乎对我不起作用,

    Private FText As String

Public Property Get Text() As String
  Text = FText
  lblText.Caption = Text
End Property

Public Property Let Text(ByVal Value As String)
  FText = Value
End Property

让我详细解释一下我在做什么,我正在创建一个命令按钮,唯一让我卡住的部分是获取控件的标题。我得到了 属性 来显示 'Text',当我输入它时设置了标题,但是当我 运行 程序时,标题被删除了!我正在执行的代码有什么问题?

我解决了!

Const m_def_Caption = "Cmd"

'Dim m_Picture As Picture
Dim m_Caption As String

Private Sub UserControl_InitProperties()
  m_Caption = m_def_Caption
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  m_Caption = PropBag.ReadProperty("Caption", m_def_Caption)
  lblText.Caption = m_Caption
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
  Call PropBag.WriteProperty("Caption", m_Caption, m_def_Caption)
End Sub

Public Property Get Caption() As String
  Caption = m_Caption
End Property

Public Property Let Caption(ByVal New_Caption As String)
  m_Caption = New_Caption
  PropertyChanged "Caption"
End Property

这行得通,感谢您的帮助,我很高兴自己能够解决这个问题。