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

📄 form1.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 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Name = "Form1"
        Me.Text = "图元的包围矩形"

    End Sub

#End Region

    Protected Overrides Sub OnPaint(ByVal e As Windows.Forms.PaintEventArgs)
        Dim g As Graphics = e.Graphics

        Dim gp1 As New GraphicsPath()
        Dim gp2 As New GraphicsPath()
        Dim gp3 As New GraphicsPath()
        Dim gp4 As New GraphicsPath()
        Dim i As Integer

        '利用路径的GetBounds函数获取图元的包围矩形,
        '并用矩形绘出包围矩形
        gp1.AddLine(New PointF(10, 10), New PointF(100, 100))
        gp2.AddEllipse(150, 100, 100, 100)
        gp3.AddArc(10, 80, 100, 100, 20, 80)
        Dim s As String = "巴蜀秋山形又瘦,岳麓红枫醉几回"
        Dim sf As StringFormat = New StringFormat(StringFormatFlags.NoWrap)
        Dim f As FontFamily = New FontFamily("隶书")
        gp4.AddString(s, f, 1, 30, New PointF(120, 50), sf)

        Dim gb1 As RectangleF = gp1.GetBounds
        Dim gb2 As RectangleF = gp2.GetBounds
        Dim gb3 As RectangleF = gp3.GetBounds
        Dim gb4 As RectangleF = gp4.GetBounds
        g.DrawPath(Pens.Black, gp1)
        g.DrawRectangle(Pens.Red, gb1.Left, gb1.Top, gb1.Width, gb1.Height)
        g.DrawPath(Pens.Black, gp2)
        g.DrawRectangle(Pens.Red, gb2.Left, gb2.Top, gb2.Width, gb2.Height)
        g.DrawPath(Pens.Black, gp3)
        g.DrawRectangle(Pens.Red, gb3.Left, gb3.Top, gb3.Width, gb3.Height)
        g.DrawPath(Pens.Blue, gp4)
        g.DrawRectangle(Pens.Red, gb4.Left, gb4.Top, gb4.Width, gb4.Height)

        '输出各图元所在路径的特殊点的个数
        Console.WriteLine(gp1.PointCount)
        Console.WriteLine(gp2.PointCount)
        Console.WriteLine(gp3.PointCount)
        Console.WriteLine(gp4.PointCount)

        '获取并输出各图元所在路径的特殊点的坐标
        Dim p1() As PointF = gp1.PathPoints()
        Dim p2() As PointF = gp2.PathPoints()
        Dim p3() As PointF = gp3.PathPoints()
        Dim p4() As PointF = gp4.PathPoints()

        Console.WriteLine("p1:{0},{1},{2},{3}", p1(0).X, p1(0).Y, p1(1).X, p1(1).Y)
        Console.WriteLine("p2:{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14}," _
                       & "{15},{16},{17},{18},{19},{20},{21},{22},{23},{24},{25}", _
                       p2(0).X, p2(0).Y, p2(1).X, p2(1).Y, p2(2).X, p2(2).Y, p2(3).X, p2(3).Y, _
                       p2(4).X, p2(4).Y, p2(5).X, p2(5).Y, p2(6).X, p2(6).Y, p2(7).X, p2(7).Y, _
                       p2(8).X, p2(8).Y, p2(9).X, p2(9).Y, p2(10).X, p2(10).Y, p2(11).X, p2(11).Y, _
                       p2(12).X, p2(12).Y)
        Console.WriteLine("p3:{0},{1},{2},{3},{4},{5},{6},{7}", _
                       p3(0).X, p3(0).Y, p3(1).X, p3(1).Y, p3(2).X, p3(2).Y, _
                       p3(3).X, p3(3).Y)
        Console.WriteLine("p4:{0},{1},{2},{3}", p4(0).X, p4(0).Y, p4(1).X, p4(1).Y)
    End Sub
End Class

⌨️ 快捷键说明

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