📄 circle.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "DrawCircle"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'自定义局部变量
Private mvarPoint1 As POINT
Private mvarPoint2 As POINT
Private mvarPoint As POINT
'保持属性值的局部变量
Private mvarColor As Long '局部复制
Public Sub SetPoint(Position As Long, x As Long, y As Long)
Select Case Position
Case 1 '设置圆心坐标
mvarPoint1.x = x
mvarPoint1.y = y
Case 2 '设置圆上一点坐标
mvarPoint2.x = x
mvarPoint2.y = y
End Select
End Sub
Public Property Let Color(ByVal vData As Long)
'向属性指派值时使用,位于赋值语句的左边。
'Syntax: X.Color = 5
mvarColor = vData
End Property
Public Property Get Color() As Long
'检索属性值时使用,位于赋值语句的右边。
'Syntax: Debug.Print X.Color
Color = mvarColor
End Property
Public Sub SetOldPoint(x As Long, y As Long)
'设置参考点坐标
mvarPoint.x = x
mvarPoint.y = y
End Sub
Public Sub Move(Drawing As Object, x As Long, y As Long, Optional Style As Long = 0)
Dim mStyle As Long
Dim mColor As Long
Dim mMode As Long
mMode = Drawing.DrawMode '保存绘图模式
mColor = Drawing.ForeColor '保存前景色
Drawing.DrawMode = 7 '设置为“异或”模式
Drawing.ForeColor = Drawing.BackColor Xor Color '设置异或模式前景色
'异或模式的前景色为复制模式前景色与绘图区背景色的异或值
'更新圆上点坐标
Drawing.Circle (mvarPoint1.x, mvarPoint1.y), Sqr((mvarPoint1.x - mvarPoint2.x) ^ 2 + (mvarPoint1.y - mvarPoint2.y) ^ 2)
Select Case Style
Case 1
mvarPoint2.x = x '更新第二点坐标
mvarPoint2.y = y
Case 2
mvarPoint2.x = x '更新第二点坐标
mvarPoint2.y = y
End Select
'重绘图元
Drawing.Circle (mvarPoint1.x, mvarPoint1.y), Sqr((mvarPoint1.x - mvarPoint2.x) ^ 2 + (mvarPoint1.y - mvarPoint2.y) ^ 2)
'恢复绘图区原始设置
Drawing.ForeColor = mColor
Drawing.DrawMode = mMode
End Sub
Private Function OnCircle(x As Long, y As Long) As Boolean
'计算点是否在圆上
If ((x - mvarPoint1.x) ^ 2 + (y - mvarPoint1.y) ^ 2) < Abs((mvarPoint1.x - mvarPoint2.x) ^ 2 + (mvarPoint1.y - mvarPoint2.y) ^ 2) + MAXDISTANCE _
And ((x - mvarPoint1.x) ^ 2 + (y - mvarPoint1.y) ^ 2) > Abs((mvarPoint1.x - mvarPoint2.x) ^ 2 - (mvarPoint1.y - mvarPoint2.y) ^ 2) + MAXDISTANCE Then
OnCircle = True
Else
OnCircle = False
End If
End Function
Public Function IsCurrent(x As Long, y As Long) As Long
'判断(X,Y)是否在当前圆上
'假设指定点不在当前圆上
IsCurrent = 0
'开始判断输入点与圆的关系
If ((x - mvarPoint1.x) ^ 2 + (y - mvarPoint1.y) ^ 2) < Abs((mvarPoint1.x - mvarPoint2.x) ^ 2 + (mvarPoint1.y - mvarPoint2.y) ^ 2) + MAXDISTANCE _
And ((x - mvarPoint1.x) ^ 2 + (y - mvarPoint1.y) ^ 2) > Abs((mvarPoint1.x - mvarPoint2.x) ^ 2 - (mvarPoint1.y - mvarPoint2.y) ^ 2) + MAXDISTANCE Then
IsCurrent = 1
ElseIf ((x - mvarPoint1.x) ^ 2 + (y - mvarPoint1.y) ^ 2) <= MAXDISTANCE ^ 2 Then
IsCurrent = 3
End If
End Function
Public Sub Draw(Drawing As Object)
'绘制圆
Dim mColor As Long
Dim mMode As Long
mMode = Drawing.DrawMode '保存绘图模式
mColor = Drawing.ForeColor '保存前景色
Drawing.DrawMode = 13 '设置为“复制”模式
Drawing.ForeColor = mvarColor '设置前景色
'绘制圆
Drawing.Circle (mvarPoint1.x, mvarPoint1.y), Sqr((mvarPoint1.x - mvarPoint2.x) ^ 2 + (mvarPoint1.y - mvarPoint2.y) ^ 2)
'恢复绘图区原始设置
Drawing.ForeColor = mColor
Drawing.DrawMode = mMode
End Sub
Public Sub Save(File As Integer)
'写圆图元数据
Write #File, 2, mvarPoint1.x, mvarPoint1.y, mvarPoint2.x, mvarPoint2.y, mvarColor
End Sub
Public Sub Load(File As Integer)
'读圆图元数据
Input #File, mvarPoint1.x, mvarPoint1.y, mvarPoint2.x, mvarPoint2.y, mvarColor
End Sub
Public Sub PrintObject(Drawing As Object)
'打印圆
Dim mColor As Long
On Error Resume Next '执行错误处理
mColor = Drawing.ForeColor '保存前景色
Drawing.ForeColor = mvarColor '设置前景色
'绘制圆
Drawing.Circle (mvarPoint1.x, mvarPoint1.y), Sqr((mvarPoint1.x - mvarPoint2.x) ^ 2 + (mvarPoint1.y - mvarPoint2.y) ^ 2)
Drawing.ForeColor = mColor '恢复前景色
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -