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

📄 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()
        components = New System.ComponentModel.Container()
        Me.Text = "Form1"
    End Sub

#End Region

    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        Dim g As Graphics = e.Graphics
        g.FillRectangle(Brushes.White, Me.ClientRectangle)
        Dim gp As GraphicsPath
        gp = Definegp()
        g.DrawPath(New Pen(Color.Black, 2), gp)
    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, _
           ByVal e As Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
        Dim g As Graphics = CreateGraphics()
        Dim gp As New GraphicsPath()
        gp = Definegp()
        Dim rect As RectangleF = gp.GetBounds
        Dim picked As Boolean = False

        '如果拾取点位于曲线的包围矩形中
        If rect.Contains(e.X, e.Y) Then
            '如果拾取点在曲线的轮廓线上可见
            If gp.IsOutlineVisible(e.X, e.Y, Pens.Black) Then
                '则曲线被拾取
                picked = True
            End If
        End If
        '曲线被拾取时用红色虚线表示,否则
        '用黑色实线表示
        If picked Then
            g.DrawPath(New Pen(Color.White, 2), gp)
            Dim aPen As New Pen(Color.Red, 2)
            aPen.DashStyle = DashStyle.Dash
            g.DrawPath(aPen, gp)
        Else
            g.DrawPath(New Pen(Color.Black, 2), gp)
        End If
    End Sub

    Private Function Definegp() As GraphicsPath
        Dim gp As New GraphicsPath()
        '定义顶点,添加基数样条曲线到路径
        Dim point1 As New Point(10, 100)
        Dim point2 As New Point(80, 20)
        Dim point3 As New Point(150, 300)
        Dim point4 As New Point(200, 100)
        Dim point5 As New Point(300, 200)
        Dim point6 As New Point(500, 150)
        Dim points As Point() = {point1, point2, point3, point4, point5, point6}
        gp.AddCurve(points)
        Return gp
    End Function
End Class

⌨️ 快捷键说明

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