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

📄 form1.vb

📁 苏金明编写的《用VB.NET和VC#.NET开发交互式CAD系统》一书的源代码
💻 VB
字号:
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 PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents line As System.Windows.Forms.Button
    Friend WithEvents ellipse As System.Windows.Forms.Button
    Friend WithEvents arc As System.Windows.Forms.Button
    Friend WithEvents poly As System.Windows.Forms.Button
    Friend WithEvents curve As System.Windows.Forms.Button
    Friend WithEvents clear As System.Windows.Forms.Button
    Friend WithEvents close As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox()
        Me.line = New System.Windows.Forms.Button()
        Me.ellipse = New System.Windows.Forms.Button()
        Me.arc = New System.Windows.Forms.Button()
        Me.poly = New System.Windows.Forms.Button()
        Me.curve = New System.Windows.Forms.Button()
        Me.clear = New System.Windows.Forms.Button()
        Me.close = New System.Windows.Forms.Button()
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.BackColor = System.Drawing.Color.White
        Me.PictureBox1.Location = New System.Drawing.Point(8, 8)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(448, 272)
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        '
        'line
        '
        Me.line.Location = New System.Drawing.Point(16, 296)
        Me.line.Name = "line"
        Me.line.Size = New System.Drawing.Size(48, 24)
        Me.line.TabIndex = 1
        Me.line.Text = "直线段"
        '
        'ellipse
        '
        Me.ellipse.Location = New System.Drawing.Point(80, 296)
        Me.ellipse.Name = "ellipse"
        Me.ellipse.Size = New System.Drawing.Size(48, 24)
        Me.ellipse.TabIndex = 2
        Me.ellipse.Text = "椭圆"
        '
        'arc
        '
        Me.arc.Location = New System.Drawing.Point(144, 296)
        Me.arc.Name = "arc"
        Me.arc.Size = New System.Drawing.Size(48, 24)
        Me.arc.TabIndex = 3
        Me.arc.Text = "圆弧"
        '
        'poly
        '
        Me.poly.Font = New System.Drawing.Font("宋体", 7.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.poly.Location = New System.Drawing.Point(208, 296)
        Me.poly.Name = "poly"
        Me.poly.Size = New System.Drawing.Size(48, 24)
        Me.poly.TabIndex = 4
        Me.poly.Text = "多义线"
        '
        'curve
        '
        Me.curve.Location = New System.Drawing.Point(272, 296)
        Me.curve.Name = "curve"
        Me.curve.Size = New System.Drawing.Size(48, 24)
        Me.curve.TabIndex = 5
        Me.curve.Text = "曲线"
        '
        'clear
        '
        Me.clear.Location = New System.Drawing.Point(336, 296)
        Me.clear.Name = "clear"
        Me.clear.Size = New System.Drawing.Size(48, 24)
        Me.clear.TabIndex = 6
        Me.clear.Text = "清除"
        '
        'close
        '
        Me.close.Location = New System.Drawing.Point(400, 296)
        Me.close.Name = "close"
        Me.close.Size = New System.Drawing.Size(48, 24)
        Me.close.TabIndex = 7
        Me.close.Text = "关闭"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(464, 342)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.close, Me.clear, Me.curve, Me.poly, Me.arc, Me.ellipse, Me.line, Me.PictureBox1})
        Me.Name = "Form1"
        Me.Text = "GDI+绘图"
        Me.ResumeLayout(False)

    End Sub

#End Region
    Private g As Graphics

    Private Sub line_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles line.Click
        g = PictureBox1.CreateGraphics()
        Dim pen1 As New Pen(Color.Blue, 3)
        pen1.DashStyle = Drawing.Drawing2D.DashStyle.DashDot
        g.DrawLine(pen1, 10, 10, 200, 200)
        Dim pen2 As New Pen(Color.Red)
        pen2.EndCap = Drawing.Drawing2D.LineCap.ArrowAnchor
        g.DrawLine(pen2, 200, 50, 20, 150)
    End Sub

    Private Sub ellipse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ellipse.Click
        g = PictureBox1.CreateGraphics()
        g.DrawEllipse(Pens.Red, 30, 50, 300, 200)
    End Sub

    Private Sub arc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles arc.Click
        g = PictureBox1.CreateGraphics()
        Dim pen As New Pen(Color.FromArgb(100, 200, 0, 200), 2)
        g.DrawArc(pen, 100, 40, 100, 100, 30, 290)
    End Sub

    Private Sub poly_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles poly.Click
        g = PictureBox1.CreateGraphics()
        Dim points() As PointF = New PointF() { _
                    New PointF(90, 10), New PointF(300, 100), _
                    New PointF(150, 200), New PointF(100, 80)}
        g.DrawPolygon(Pens.BlueViolet, points)
    End Sub

    Private Sub curve_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles curve.Click
        g = PictureBox1.CreateGraphics()
        Dim pen As New Pen(Color.Cyan, 2)
        pen.DashStyle = Drawing.Drawing2D.DashStyle.DashDotDot
        g.DrawBezier(pen, New PointF(90, 10), New PointF(300, 100), _
                    New PointF(150, 200), New PointF(100, 80))
        Dim points() As PointF = New PointF() { _
                   New PointF(90, 10), New PointF(300, 100), _
                   New PointF(150, 200), New PointF(100, 80)}
        g.DrawCurve(Pens.Blue, points)
    End Sub

    Private Sub clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear.Click
        g = PictureBox1.CreateGraphics()
        g.Clear(Color.White)
    End Sub

    Private Sub close_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles close.Click
        Me.Dispose()
    End Sub
End Class

⌨️ 快捷键说明

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