cgelement.vb
来自「苏金明编写的《用VB.NET和VC#.NET开发交互式CAD系统》一书的源代码」· VB 代码 · 共 136 行
VB
136 行
'图元基类
Imports System.Drawing.Drawing2D
Public Class CGElement
'绘图方式
Public Enum geDrawMode
Normal = 1
Selec = 2
Drag = 3
Delete = 4
End Enum
'图元的线型
Public Enum geStyle
Solid = 1
Dash = 2
Dot = 3
DashDot = 4
DashDotDot = 5
End Enum
Private m_Color, m_Style, m_Width As Integer
'颜色属性
Public Property Color() As Integer
Get
Return m_Color
End Get
Set(ByVal newValue As Integer)
m_Color = newValue
End Set
End Property
'线型属性
Public Property Style() As Integer
Get
Return m_Style
End Get
Set(ByVal newValue As Integer)
m_Style = newValue
End Set
End Property
'线宽属性
Public Property Width() As Integer
Get
Return m_Width
End Get
Set(ByVal newValue As Integer)
m_Width = newValue
End Set
End Property
'构造函数
Public Sub New()
Init()
End Sub
'初始化图元
Public Sub Init()
m_Style = 0
m_Width = 1
m_Color = RGB(0, 0, 0)
End Sub
'绘制图元
Public Overridable Sub Draw(ByVal g As Graphics, _
ByVal aGrawMode As geDrawMode)
End Sub
'平移图元
Public Overridable Sub Move(ByVal g As Graphics, _
ByVal basePos As PointF, ByVal desPos As PointF)
End Sub
'旋转图元
Public Overridable Sub Rotate(ByVal g As Graphics, _
ByVal basePos As PointF, ByVal aAngle As Single)
End Sub
'镜像图元
Public Overridable Sub Mirror(ByVal g As Graphics, _
ByVal pPos1 As PointF, ByVal pPos2 As PointF)
End Sub
'比例缩放图元
Public Overridable Sub Scale(ByVal g As Graphics, _
ByVal scalex As Single, ByVal scaley As Single)
End Sub
'获取图元的包围矩形
Public Overridable Function GetBox() As CBox
End Function
'拾取图元
Public Overridable Function Pick(ByVal aPos As PointF, _
ByVal PickRadius As Single) As Boolean
End Function
'根据不同的绘图模式设置不同的绘图参数
Public Function DrawSettings(ByVal hdc As IntPtr, _
ByVal aDrawMode As geDrawMode) As Integer()
Dim penPara(2) As Integer
Select Case aDrawMode
Case geDrawMode.Normal
Win32API.SetROP2(hdc, 13)
m_Style = 0
m_Width = 1
m_Color = RGB(0, 0, 0)
Case geDrawMode.Selec
Win32API.SetROP2(hdc, 13)
m_Style = 1
m_Width = 1
m_Color = RGB(255, 0, 0)
Case geDrawMode.Drag
Win32API.SetROP2(hdc, 10)
m_Style = 0
m_Width = 1
m_Color = RGB(0, 0, 255)
Case geDrawMode.Delete
Win32API.SetROP2(hdc, 13)
m_Style = 0
m_Width = 1
m_Color = RGB(255, 255, 255)
End Select
penPara(0) = m_Style
penPara(1) = m_Width
penPara(2) = m_Color
Return penPara
End Function
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?