首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

关于OCX自定义属性,该如何解决

2012-01-30 
关于OCX自定义属性小的想创建第一个OCX,只在OCX中放置一个label控件,调用者的Caption属性即label的Caption

关于OCX自定义属性
小的想创建第一个OCX,只在OCX中放置一个label控件,调用者的Caption属性即label的Caption属性,只想用代码完成,程序如下:  
'自定义属性  

Public   Property   Get   Caption()   As   String  

Caption   =   Label11.Caption  

End   Property  

Public   Property   Let   Caption(ByVal   NewCaption   As   String)  

Label1.Caption   =   NewCaption  

VB.UserControl.PropertyChanged   "Caption "  

End   Property  


Private   Sub   UserControl_InitProperties()   '初始化属性  

Caption   =   VB.UserControl.Extender.Name  

End   Sub  


Private   Sub   UserControl_ReadProperties(ProBag   As   PropertyBag)   '读属性  

VBRUN.PropBag.ReadProperty   "Caption "  

End   Sub  

Private   Sub   UserControl_WriteProperties(PropBag   As   PropertyBag)   '写属性  

VBRUN.PropBag.WriteProperty   "Caption ",   Caption  

End   Sub  

结果屡试不成...请赐教T   T  
问题不是很难,请高手务必指点T   T  
要不小的必死矣T   T

[解决办法]
Public Property Get Caption() As String

Caption = Label1.Caption

End Property

Public Property Let Caption(ByVal NewCaption As String)

Label1.Caption = NewCaption

PropertyChanged "Caption "

End Property


Private Sub Label1_Click()

End Sub

Private Sub UserControl_InitProperties() '初始化属性

Caption = Extender.Name

End Sub


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

热点排行