cgelement.vb
来自「苏金明编写的《用VB.NET和VC#.NET开发交互式CAD系统》一书的源代码」· VB 代码 · 共 105 行
VB
105 行
'图元基类
Public MustInherit 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 Value As Integer)
m_Color = Value
End Set
End Property
'线型属性
Public Property Style() As Integer
Get
Return m_Style
End Get
Set(ByVal Value As Integer)
m_Style = Value
End Set
End Property
'线宽属性
Public Property Width() As Integer
Get
Return m_Width
End Get
Set(ByVal Value As Integer)
m_Width = Value
End Set
End Property
'构造函数
Public Sub New()
Init()
End Sub
'初始化图元
Protected Sub Init()
m_Style = 0
m_Width = 1
m_Color = RGB(0, 0, 0)
End Sub
'绘制图元
Public MustOverride Sub Draw(ByVal g As Graphics, _
ByVal aGrawMode As geDrawMode)
'根据不同的绘图模式设置不同的绘图参数
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 + -
显示快捷键?