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

📄 form1.vb

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

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

    <StructLayout(LayoutKind.Sequential)> Public Structure LPPOINT
        Public x As Long
        Public y As Long
    End Structure

    <DllImport("gdi32.dll")> _
     Private Shared Function SetROP2(ByVal hdc As IntPtr, _
         ByVal nDrawMode As Integer) As Boolean
    End Function

    <DllImport("gdi32.dll")> _
    Private Shared Function Rectangle _
        (ByVal hdc As IntPtr, ByVal X1 As Integer, ByVal Y1 As Integer, _
        ByVal X2 As Integer, ByVal Y2 As Integer) As Boolean
    End Function

    <DllImport("gdi32.dll")> _
    Private Shared Function CreatePen(ByVal nPenStyle As Integer, _
        ByVal nWidth As Integer, ByVal crColor As Long) As Long
    End Function

    <DllImport("gdi32.dll")> _
    Private Shared Function SelectObject(ByVal hdc As IntPtr, _
        ByVal hObject As Long) As Long
    End Function

    <DllImport("gdi32.dll")> _
    Private Shared Function DeleteObject(ByVal hObject As Long) As Long
    End Function

    '绘矩形
    Public Sub Draw(ByVal aGraphics As Graphics, ByVal aColor As Long)
        Dim hdc As IntPtr
        hdc = aGraphics.GetHdc
        SetROP2(hdc, 10)
        Dim p As Long
        Dim oldP As Long
        p = CreatePen(0, 1, aColor)
        oldP = SelectObject(hdc, p)
        Rectangle(hdc, 20, 150, 170, 250)
        SelectObject(hdc, oldP)
        DeleteObject(p)
        aGraphics.ReleaseHdc(hdc)
    End Sub

    Public Sub Form1_Paint(ByVal sender As Object, ByVal e As Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim g As Graphics = e.Graphics
        g.FillRectangle(Brushes.White, Me.ClientRectangle)
        '用GDI+函数绘一个兰色矩形
        g.DrawRectangle(Pens.Blue, 20, 20, 150, 100)
        '用API函数绘一个红色矩形
        Draw(g, RGB(255, 0, 0))
    End Sub
End Class

⌨️ 快捷键说明

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