有关 VB 制作用户控件 的问题

来源:百度知道 编辑:UC知道 时间:2024/06/22 06:23:55
我想给制作的用户控件添上一个属性caption并且使用户控件里的label1.caption和控件的caption里的一样
也就是像许多自制的按钮控件那样子

将下面语句添加到你的用户控件模块中

Public Property Get Caption() As String
Caption = Label1.Caption
End Property

Public Property Let Caption(ByVal vNewValue As String)
Label1.Caption = vNewValue
End Property

'补充,我明白你的意思了=======================
’将下面语句再添加到你的用户控件模块中
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Label1.Caption = PropBag.ReadProperty("Caption", "Label1")
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
PropBag.WriteProperty "Caption", Label1.Caption, "Label1"
End Sub