Public
Event Click() 注释:定义该控件要产生的事件
Dim
CircleX
As
Integer
,CircleY
As
Integer
Private
Sub
UserControl_Click() RaiseEvent Click 注释:触发Click事件
End Sub
Private
Sub
UserControl_Initialize() CircleX
=
Shape1.Width
/
2
CircleY
=
Shape1.Height
/
2
End Sub
Private
Sub
UserControl_MouseDown(Button
As
Integer
,Shift
As
Integer
,X
As
Single
,Y
As
Single
) Shape1.BackColor
=
RGB
(
0
,
0
,
255
)
End Sub
Private
Sub
UserControl_MouseMove(Button
As
Integer
,Y
As
Single
)
Dim
MoveX
As
Integer
,MoveY
As
Integer
MoveX
=
X
-
Shape1.Width
/
2
MoveY
=
Y
-
Shape1.Height
/
2
If
(MoveX
<
0
)
Or
(MoveX
+
Shape1.Width
>
UserControl.ScaleWidth)
Or
_ (MoveY
<
0
)
Or
(MoveY
+
Shape1.Height
>
UserControl.ScaleHeight)
Then
Exit
Sub
Shape1.Move MoveX,MoveY
End Sub
Private
Sub
UserControl_MouseUp(Button
As
Integer
,Y
As
Single
) Shape1.BackColor
=
RGB
(
255
,
0
)
End Sub
Property
Get
PosX()
As
Integer
注释:取得CircleX的值显示给用户 PosX
=
CircleX
End Property
Property
Let
PosX(ByVal New_X
As
Integer
) 注释:把用户写入的值设置到OCX控件内部
If
(New_X
<
Shape1.Width
/
2
)
Or
_ (New_X
>
UserControl.ScaleWidth
-
Shape1.Width
/
2
)
Then
MsgBox (
"
圆的X值超出界限了
"
)
Else
CircleX
=
New_X
Call
UserControl_Resize
End
If
End Property
Property
Get
PosY()
As
Integer
PosY
=
CircleY
End Property
Property
Let
PosY(ByVal New_Y
As
Integer
)
If
(New_Y
<
Shape1.Height
/
2
)
Or
_ (New_Y
>
UserControl.ScaleHeight
-
Shape1.Height
/
2
)
Then
MsgBox (
"
圆的Y值超出界限了
"
)
Else
CircleY
=
New_Y
Call
UserControl_Resize
End
If
End Property
Private
Sub
UserControl_ReadProperties(PropBag
As
PropertyBag) CircleX
=
PropBag.ReadProperty(
"
CircleX
"
,Shape1.Width
/
2
) 注释:将用户设置的值读出来 CircleY
=
PropBag.ReadProperty(
"
CircleY
"
,Shape1.Height
/
2
) 注释:同上
Call
UserControl_Resize
End Sub
Private
Sub
UserControl_Resize() Shape1.Move CircleX,CircleY
End Sub
Private
Sub
UserControl_WriteProperties(PropBag
As
PropertyBag)
Call
PropBag.WriteProperty(
"
CircleX
"
,CircleX,Shape1.Width
/
2
) 注释:将用户设置的值保存
Call
PropBag.WriteProperty(
"
CircleY
"
,CircleY,Shape1.Height
/
2
) 注释:同上
End Sub