一、属性的派生
Public Property Let 属性名(ByVal NewValue As 类型名)
PropertyChanged "属性名"
End Property
Public Property Get 属性名() As 类型名
End Property
如果是只读的属性,缺省Let过程即可。
二、方法的派生
Public Sub 方法名(参数表)
End Sub
Public Function 方法名(参数表) As 类型名
End Function
三、事件的派生
'申明部分
Public Event 事件名(参数表)
'激活部分
RaiseEvent 事件名(参数表)
四、UserControl自有事件
InitProperties:创建对象的新实例时,发生该事件。
Initialize:父对象创建UserControl时,发生该事件。
Resize:大小改变时,发生该事件。
ReadProperties:当加载具有保存状态的对象的旧实例时,发生该事件。
内部过程:Set 对象名= PropBag.ReadProperty("属性名", 默认值)
WriteProperties:当保存对象的实例时(由PropertyChanged引发),发生该事件。
内部过程:Call PropBag.WriteProperty("属性名", 属性值, 默认值)
五、UserControl固有过程
(1)字体部分
Private WithEvents mFont As StdFont
Private Sub UserControl_Initialize()
Set mFont = New StdFont
Set UserControl.Font = mFont
End Sub
Public Property Get Font() As StdFont
Set Font = UserControl.Font
End Property
Private Sub mFont_FontChanged(ByVal PropertyName As String)
Set UserControl.Font = mFont
Refresh
End Sub
Public Property Set Font(mnewFont As StdFont)
With mFont
.Bold = mnewFont.Bold
.Charset = mnewFont.Charset
.Italic = mnewFont.Italic
.Name = mnewFont.Name
.Size = mnewFont.Size
.Strikethrough = mnewFont.Strikethrough
.Underline = mnewFont.Underline
.Weight = mnewFont.Weight
End With
PropertyChanged "Font"
End Property
(2)光标、鼠标、句柄部分
'注意!不要删除或修改下列被注释的行!
'MappingInfo=UserControl,UserControl,-1,MouseIcon
Public Property Get MouseIcon() As Picture
Set MouseIcon = UserControl.MouseIcon
End Property
Public Property Set MouseIcon(ByVal New_MouseIcon As Picture)
Set UserControl.MouseIcon = New_MouseIcon
PropertyChanged "MouseIcon"
End Property
'注意!不要删除或修改下列被注释的行!
'MappingInfo=UserControl,UserControl,-1,HasDC
Public Property Get HasDC() As Boolean
HasDC = UserControl.HasDC
End Property
'注意!不要删除或修改下列被注释的行!
'MappingInfo=UserControl,UserControl,-1,hDC
Public Property Get hDC() As Long
hDC = UserControl.hDC
End Property
'注意!不要删除或修改下列被注释的行!
'MappingInfo=UserControl,UserControl,-1,hWnd
Public Property Get hwnd() As Long
hwnd = UserControl.hwnd
End Property
六、UserControl对象
Public属性:决定是调用形式使用还是以ActiveX方式使用。
BackStyle属性:在父对象中是否透明。
又看见你了,你好