⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgelement.vb

📁 苏金明编写的《用VB.NET和VC#.NET开发交互式CAD系统》一书的源代码
💻 VB
字号:
'图元基类

<Serializable()> 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 MustOverride Sub Move(ByVal g As Graphics, _
        ByVal basePos As PointF, ByVal desPos As PointF)

    '旋转图元
    Public MustOverride Sub Rotate(ByVal g As Graphics, _
        ByVal basePos As PointF, ByVal aAngle As Single)

    '镜像图元
    Public MustOverride Sub Mirror(ByVal g As Graphics, _
        ByVal pPos1 As PointF, ByVal pPos2 As PointF)

    '比例缩放图元
    Public MustOverride Sub Scale(ByVal g As Graphics, _
        ByVal scalex As Single, ByVal scaley As Single)

    '获取图元的包围矩形
    Public MustOverride Function GetBox() As CBox

    '拾取图元
    Public MustOverride Function Pick(ByVal aPos As PointF) As Boolean

    '根据不同的绘图模式设置不同的绘图参数
    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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -