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

📄 drawmain.vb

📁 苏金明编写的《用VB.NET和VC#.NET开发交互式CAD系统》一书的源代码
💻 VB
字号:
Imports System.Drawing.Drawing2D

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写处置以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意:以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents MenuItem6 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem11 As System.Windows.Forms.MenuItem
    Friend WithEvents MenuItem13 As System.Windows.Forms.MenuItem
    Friend WithEvents line As System.Windows.Forms.MenuItem
    Friend WithEvents sel As System.Windows.Forms.MenuItem
    Friend WithEvents desel As System.Windows.Forms.MenuItem
    Friend WithEvents tmove As System.Windows.Forms.MenuItem
    Friend WithEvents trotate As System.Windows.Forms.MenuItem
    Friend WithEvents tmirror As System.Windows.Forms.MenuItem
    Friend WithEvents tzoomout As System.Windows.Forms.MenuItem
    Friend WithEvents tzoomin As System.Windows.Forms.MenuItem
    Friend WithEvents tdelete As System.Windows.Forms.MenuItem
    Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
    Friend WithEvents Panel1 As System.Windows.Forms.StatusBarPanel
    Friend WithEvents selAll As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim configurationAppSettings As System.Configuration.AppSettingsReader = New System.Configuration.AppSettingsReader()
        Me.MainMenu1 = New System.Windows.Forms.MainMenu()
        Me.MenuItem6 = New System.Windows.Forms.MenuItem()
        Me.line = New System.Windows.Forms.MenuItem()
        Me.MenuItem11 = New System.Windows.Forms.MenuItem()
        Me.sel = New System.Windows.Forms.MenuItem()
        Me.selAll = New System.Windows.Forms.MenuItem()
        Me.desel = New System.Windows.Forms.MenuItem()
        Me.MenuItem13 = New System.Windows.Forms.MenuItem()
        Me.tmove = New System.Windows.Forms.MenuItem()
        Me.trotate = New System.Windows.Forms.MenuItem()
        Me.tmirror = New System.Windows.Forms.MenuItem()
        Me.tzoomout = New System.Windows.Forms.MenuItem()
        Me.tzoomin = New System.Windows.Forms.MenuItem()
        Me.tdelete = New System.Windows.Forms.MenuItem()
        Me.StatusBar1 = New System.Windows.Forms.StatusBar()
        Me.Panel1 = New System.Windows.Forms.StatusBarPanel()
        CType(Me.Panel1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'MainMenu1
        '
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem6, Me.MenuItem11})
        '
        'MenuItem6
        '
        Me.MenuItem6.Index = 0
        Me.MenuItem6.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.line})
        Me.MenuItem6.Text = "绘图"
        '
        'line
        '
        Me.line.Index = 0
        Me.line.Text = "直线段"
        '
        'MenuItem11
        '
        Me.MenuItem11.Index = 1
        Me.MenuItem11.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.sel, Me.selAll, Me.desel, Me.MenuItem13, Me.tdelete})
        Me.MenuItem11.Text = "编辑"
        '
        'sel
        '
        Me.sel.Index = 0
        Me.sel.Text = "选择"
        '
        'selAll
        '
        Me.selAll.Index = 1
        Me.selAll.Text = "全选"
        '
        'desel
        '
        Me.desel.Index = 2
        Me.desel.Text = "放弃选择"
        '
        'MenuItem13
        '
        Me.MenuItem13.Index = 3
        Me.MenuItem13.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.tmove, Me.trotate, Me.tmirror, Me.tzoomout, Me.tzoomin})
        Me.MenuItem13.Text = "变换"
        '
        'tmove
        '
        Me.tmove.Index = 0
        Me.tmove.Text = "平移"
        '
        'trotate
        '
        Me.trotate.Index = 1
        Me.trotate.Text = "旋转"
        '
        'tmirror
        '
        Me.tmirror.Index = 2
        Me.tmirror.Text = "镜像"
        '
        'tzoomout
        '
        Me.tzoomout.Index = 3
        Me.tzoomout.Text = "缩小"
        '
        'tzoomin
        '
        Me.tzoomin.Index = 4
        Me.tzoomin.Text = "放大"
        '
        'tdelete
        '
        Me.tdelete.Index = 4
        Me.tdelete.Text = "删除"
        '
        'StatusBar1
        '
        Me.StatusBar1.Enabled = CType(configurationAppSettings.GetValue("StatusBar1.Enabled", GetType(System.Boolean)), Boolean)
        Me.StatusBar1.Location = New System.Drawing.Point(0, 369)
        Me.StatusBar1.Name = "StatusBar1"
        Me.StatusBar1.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.Panel1})
        Me.StatusBar1.ShowPanels = CType(configurationAppSettings.GetValue("StatusBar1.ShowPanels", GetType(System.Boolean)), Boolean)
        Me.StatusBar1.Size = New System.Drawing.Size(552, 16)
        Me.StatusBar1.SizingGrip = CType(configurationAppSettings.GetValue("StatusBar1.SizingGrip", GetType(System.Boolean)), Boolean)
        Me.StatusBar1.TabIndex = 0
        Me.StatusBar1.Text = CType(configurationAppSettings.GetValue("StatusBar1.Text", GetType(System.String)), String)
        '
        'Panel1
        '
        Me.Panel1.Text = "就绪"
        Me.Panel1.ToolTipText = "当前位置"
        Me.Panel1.Width = 200
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.Color.White
        Me.ClientSize = New System.Drawing.Size(552, 385)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.StatusBar1})
        Me.Menu = Me.MainMenu1
        Me.Name = "Form1"
        Me.Text = "Net_CAD"
        Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
        CType(Me.Panel1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub MenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim g As Graphics = Me.CreateGraphics()
        g.FillRectangle(Brushes.White, Me.ClientRectangle)
        g.PageUnit = GraphicsUnit.Pixel

        '相对于X轴进行镜像变换
        Dim mat As New Matrix(1, 0, 0, -1, 0, 0)
        g.Transform = mat
        Dim rect As Rectangle = Me.ClientRectangle
        Dim w As Integer = rect.Width
        Dim h As Integer = rect.Height
        viewDX = rect.Width / 2
        viewDY = rect.Height / 2

        Coordinate(g)

        aCommand = creLine
    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim g As Graphics = e.Graphics
        DrawAll(g)
        DrawSel(g)
    End Sub

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
        Dim g As Graphics = Me.CreateGraphics()
        Dim aPos As PointF = PagetoWorld(New PointF(e.X, e.Y))
        If e.Button = MouseButtons.Left Then
            aCommand.LButtonDown(g, aPos)

        ElseIf e.Button = MouseButtons.Right Then
            aCommand.RButtonDown(g, aPos)
        End If
    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
        Dim g As Graphics = Me.CreateGraphics()
        Dim aPos As PointF = PagetoWorld(New PointF(e.X, e.Y))
        StatusBar1.Panels.Item(0).Text = "X=" & Str(aPos.X) & ",  Y=" & Str(aPos.Y)
        aCommand.MouseMove(g, aPos)
    End Sub

    Private Sub MenuItem7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles line.Click
        aCommand = creLine
    End Sub

    Private Sub MenuItem12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sel.Click
        aCommand = selected
    End Sub

    Private Sub MenuItem28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles desel.Click
        Dim g As Graphics = Me.CreateGraphics
        Dim i As Integer
        For i = 0 To geSels.Count - 1
            geSels(i).Draw(g, geDrawMode.Normal)
        Next i
        geSels.RemoveRange(0, geSels.Count)
    End Sub

    Private Sub MenuItem14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmove.Click
        aCommand = transMove
    End Sub

    Private Sub MenuItem15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trotate.Click
        aCommand = transRotate
    End Sub

    Private Sub MenuItem16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmirror.Click
        aCommand = transMirror
    End Sub

    Private Sub MenuItem17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tzoomout.Click
        Dim g As Graphics = Me.CreateGraphics()
        ScaleZoom(g, 0.8, 0.8)
    End Sub

    Private Sub MenuItem19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tdelete.Click
        'aCommand = Delete
    End Sub

    Private Sub tzoomin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tzoomin.Click
        Dim g As Graphics = Me.CreateGraphics()
        ScaleZoom(g, 1.2, 1.2)
    End Sub

    Private Sub selAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles selAll.Click
        Dim g As Graphics = Me.CreateGraphics
        Dim i As Integer
        For i = 0 To ges.Count - 1
            geSels.Add(ges(i))
        Next
        DrawSel(g)
    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -