ActiveX

Листинг для Урока 1

ActiveX Control "ZygZag"

'*****************************************************************
'Урок 1
'ActiveX Control - "ZygZag"
'Листинг
'*****************************************************************

Option Explicit

'*****************************************************************
'Объявление внутренних переменных
'*****************************************************************
Private Motion As Integer

'*****************************************************************
'Объявление нумерованных констант
'*****************************************************************
Public Enum constBorderStyle
Нет = 0
Окантовка = 1
End Enum

'*****************************************************************
'Объявление событий
'*****************************************************************
Event Click()
Event DblClick()
Event MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Event MouseMove(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Event MouseUp(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Event CaptionClick()

'*****************************************************************
'Свойства контрола
'*****************************************************************
Public Property Get BackColor() As OLE_COLOR
BackColor = UserControl.BackColor
End Property

Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
UserControl.BackColor() = New_BackColor
PropertyChanged "BackColor"
End Property

Public Property Get ForeColor() As OLE_COLOR
ForeColor = lblCaption.ForeColor
End Property

Public Property Let ForeColor(ByVal New_ForeColor As OLE_COLOR)
lblCaption.ForeColor() = New_ForeColor
PropertyChanged "ForeColor"
End Property

Public Property Get Font() As Font
Set Font = lblCaption.Font
End Property

Public Property Set Font(ByVal New_Font As Font)
Set lblCaption.Font = New_Font
PropertyChanged "Font"
End Property

Public Property Get BorderStyle() As constBorderStyle
BorderStyle = UserControl.BorderStyle
End Property

Public Property Let BorderStyle(ByVal New_BorderStyle As constBorderStyle)
UserControl.BorderStyle() = New_BorderStyle
PropertyChanged "BorderStyle"
End Property

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

Public Property Let Caption(ByVal New_Caption As String)
lblCaption.Caption() = New_Caption
PropertyChanged "Caption"
End Property

Public Property Get Interval() As Long
Interval = Timer1.Interval
End Property

Public Property Let Interval(ByVal New_Interval As Long)
Timer1.Interval() = New_Interval
PropertyChanged "Interval"
End Property

Public Property Get TimerOn() As Boolean
TimerOn = Timer1.Enabled
End Property

Public Property Let TimerOn(ByVal New_TimerOn As Boolean)
Timer1.Enabled() = New_TimerOn
PropertyChanged "TimerOn"
End Property

'*****************************************************************
'Обработка событий UserControl и контрола ZygZag
'*****************************************************************
Private Sub UserControl_Click()
RaiseEvent Click
End Sub

Private Sub UserControl_DblClick()
RaiseEvent DblClick
End Sub

Private Sub UserControl_MouseDown(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub

Private Sub UserControl_MouseMove(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub

Private Sub UserControl_MouseUp(Button As Integer, _
Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseUp(Button, Shift, X, Y)
End Sub

Private Sub lblCaption_Click()
RaiseEvent CaptionClick
End Sub

Private Sub UserControl_Resize()
lblCaption.Move (UserControl.Width - lblCaption.Width) / 2, _
(UserControl.Height - lblCaption.Height) / 2
Motion = 1
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
UserControl.BackColor = PropBag.ReadProperty("BackColor", &H8000000F)
lblCaption.ForeColor = PropBag.ReadProperty("ForeColor", &H80000012)
Set lblCaption.Font = PropBag.ReadProperty("Font", Ambient.Font)
UserControl.BorderStyle = PropBag.ReadProperty("BorderStyle", 0)
lblCaption.Caption = PropBag.ReadProperty("Caption", "ZygZag")
Timer1.Interval = PropBag.ReadProperty("Interval", 0)
Timer1.Enabled = PropBag.ReadProperty("TimerOn", True)
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("BackColor", UserControl.BackColor, &H8000000F)
Call PropBag.WriteProperty("ForeColor", lblCaption.ForeColor, &H80000012)
Call PropBag.WriteProperty("Font", lblCaption.Font, Ambient.Font)
Call PropBag.WriteProperty("BorderStyle", UserControl.BorderStyle, 0)
Call PropBag.WriteProperty("Caption", lblCaption.Caption, "ZygZag")
Call PropBag.WriteProperty("Interval", Timer1.Interval, 0)
Call PropBag.WriteProperty("TimerOn", Timer1.Enabled, True)
End Sub

'*****************************************************************
'Внутренние процедуры
'*****************************************************************
Private Sub MoveZygZag()
Select Case Motion
Case 1
lblCaption.Move lblCaption.Left - 50, lblCaption.Top - 50
If lblCaption.Left <= 0 Then
Motion = 2
ElseIf lblCaption.Top <= 0 Then
Motion = 4
End If
Case 2
lblCaption.Move lblCaption.Left + 50, lblCaption.Top - 50
If lblCaption.Left >= (UserControl.Width - lblCaption.Width) Then
Motion = 1
ElseIf lblCaption.Top <= 0 Then
Motion = 3
End If
Case 3
lblCaption.Move lblCaption.Left + 50, lblCaption.Top + 50
If lblCaption.Left >= (UserControl.Width - lblCaption.Width) Then
Motion = 4
ElseIf lblCaption.Top >= (UserControl.Height - lblCaption.Height) Then
Motion = 2
End If
Case 4
lblCaption.Move lblCaption.Left - 50, lblCaption.Top + 50
If lblCaption.Left <= 0 Then
Motion = 3
ElseIf lblCaption.Top >= (UserControl.Height - lblCaption.Height) Then
Motion = 1
End If
End Select
End Sub

Private Sub Timer1_Timer()
MoveZygZag
End Sub

К статье

Hosted by uCoz