【问题标题】:Add property to user control in vb6在 vb6 中向用户控件添加属性
【发布时间】:2020-06-15 16:55:14
【问题描述】:

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

    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

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

【问题讨论】:

    标签: properties vb6 user-controls activex


    【解决方案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
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-14
      • 2012-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多