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

时间:2016-12-11 15:44:05

标签: properties vb6 user-controls activex

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

    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

让我解释一下我正在做的事情,我正在创建一个命令按钮,我唯一被困住的部分是获取控件的标题。我得到的财产显示'文字'当我输入它时设置标题但是当我运行程序时标题被删除!我正在做的代码出了什么问题?

1 个答案:

答案 0 :(得分:1)

我解决了!

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

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