📄 ccircle.vb
字号:
Imports System.Drawing.Drawing2D
Imports System.Math
Public Class CCircle
Inherits GESelecter
Private m_Center, m_pCircle As PointF
'圆心
Public Property Center() As PointF
Get
Return m_Center
End Get
Set(ByVal newValue As PointF)
m_Center = newValue
End Set
End Property
'圆上一点
Public Property pCircle() As PointF
Get
Return m_pCircle
End Get
Set(ByVal newValue As PointF)
m_pCircle = newValue
End Set
End Property
'半径属性,只读
Public ReadOnly Property Radius() As Single
Get
Dim r As Single
r = DistPtoP(m_Center, m_pCircle)
Return r
End Get
End Property
'计算点与点之间的距离
Private Function DistPtoP(ByVal p1 As PointF, _
ByVal p2 As PointF) As Single
Dim dx As Single
Dim dy As Single
dx = p2.X - p1.X
dy = p2.Y - p1.Y
Return Sqrt((dx * dx) + (dy * dy))
End Function
'无参构造函数
Public Sub New()
End Sub
'构造函数,用已知的两点构造圆
Public Sub New(ByVal pCenter As PointF, ByVal pCir As PointF)
m_Center = pCenter
m_pCircle = pCir
End Sub
'绘圆
Public Overrides Sub Draw(ByVal g As Graphics, _
ByVal aDrawMode As geDrawMode)
Dim pen As Pen = DrawSettings(aDrawMode)
g.DrawEllipse(pen, m_Center.X - Radius, _
m_Center.X - Radius, Radius * 2, Radius * 2)
End Sub
'拾取圆
Public Overrides Function Pick(ByVal aPos As PointF) As Boolean
Dim gp As New GraphicsPath()
gp.AddEllipse(m_Center.X - Radius, m_Center.X - Radius, _
Radius * 2, Radius * 2)
If gp.GetBounds.Contains(aPos) Then
If gp.IsOutlineVisible(aPos, Pens.Black) Then
gp.Dispose()
Return True
Else
gp.Dispose()
Return False
End If
Else
gp.Dispose()
Return False
End If
End Function
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -