📄 cpcircle.vb
字号:
Imports System.Math
Public Class CPCircle
Inherits DrawCircle
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
'无参构造函数
Public Sub New()
End Sub
'构造函数,用已知的两点构造圆
Public Sub New(ByVal pCenter As PointF, ByVal pCir As PointF)
m_Center = pCenter
m_pCircle = pCir
End Sub
'计算点与点之间的距离
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 Overrides Sub Draw(ByVal g As Graphics)
g.DrawEllipse(Pens.Red, m_Center.X - Radius, _
m_Center.X - Radius, Radius * 2, Radius * 2)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -