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

📄 form1.vb

📁 Mastering VBNet Include Source Code
💻 VB
字号:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents PrintDocument1 As System.Drawing.Printing.PrintDocument
    Friend WithEvents PrintPreviewDialog1 As System.Windows.Forms.PrintPreviewDialog

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.Container

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.Button1 = New System.Windows.Forms.Button()
        Me.PrintDocument1 = New System.Drawing.Printing.PrintDocument()
        Me.PrintPreviewDialog1 = New System.Windows.Forms.PrintPreviewDialog()
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Font = New System.Drawing.Font("Comic Sans MS", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte))
        Me.Button1.Location = New System.Drawing.Point(24, 24)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(256, 56)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Print Rotated Strings"
        '
        'PrintPreviewDialog1
        '
        Me.PrintPreviewDialog1.AutoScrollMargin = New System.Drawing.Size(0, 0)
        Me.PrintPreviewDialog1.AutoScrollMinSize = New System.Drawing.Size(0, 0)
        Me.PrintPreviewDialog1.ClientSize = New System.Drawing.Size(400, 300)
        Me.PrintPreviewDialog1.Enabled = True
        Me.PrintPreviewDialog1.Location = New System.Drawing.Point(22, 22)
        Me.PrintPreviewDialog1.MaximumSize = New System.Drawing.Size(0, 0)
        Me.PrintPreviewDialog1.Name = "PrintPreviewDialog1"
        Me.PrintPreviewDialog1.Opacity = 1
        Me.PrintPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty
        Me.PrintPreviewDialog1.Visible = False
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(296, 133)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1})
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim Tx, Ty As Integer
        e.Graphics.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
        ' Tx, Ty ARE THE COORDINATES OF THE CENTER POINT ON THE PAGE
        Tx = e.PageSettings.PaperSize.Width / 2
        Ty = e.PageSettings.PaperSize.Height / 2
        ' DRAW A CROSSHAIR LINE AT THE MIDDLE OF THE PAGE
        e.Graphics.DrawLine(New Pen(Color.Red, 2), Tx, 0, Tx, Ty * 2)
        e.Graphics.DrawLine(New Pen(Color.Red, 2), 0, Ty, Tx * 2, Ty)

        Dim fnt As Font = New Font("Comic Sans MS", 24, FontStyle.Bold)
        Dim RectSize As SizeF
        Dim Rect As Rectangle

        ' PRINT STRING WITHOUT ROTATION
        e.Graphics.TranslateTransform(Tx, Ty)
        e.Graphics.DrawString("GDI+ Graphics (0)", fnt, _
                               Brushes.Black, 0, 0)
        RectSize = e.Graphics.MeasureString("GDI+ Graphics (0)", fnt)
        Rect = New Rectangle(0, 0, RectSize.Width, RectSize.Height)
        e.Graphics.DrawRectangle(Pens.Green, Rect)

        ' PRINT STRING ROTATED 90 DEGREES
        e.Graphics.ResetTransform()
        e.Graphics.TranslateTransform(Tx, Ty)
        e.Graphics.RotateTransform(90)
        e.Graphics.DrawString("GDI+ Graphics (90)", fnt, _
                               Brushes.Black, 0, 0)
        RectSize = e.Graphics.MeasureString("GDI+ Graphics (90)", fnt)
        Rect = New Rectangle(0, 0, RectSize.Width, RectSize.Height)
        e.Graphics.DrawRectangle(Pens.Green, Rect)

        ' PRINT STRING ROTATED 270 DEGREES
        e.Graphics.ResetTransform()
        e.Graphics.TranslateTransform(Tx, Ty)
        e.Graphics.RotateTransform(270)
        e.Graphics.DrawString("GDI+ Graphics (270)", fnt, _
                               Brushes.Black, 0, 0)
        RectSize = e.Graphics.MeasureString("GDI+ Graphics (270)", fnt)
        Rect = New Rectangle(0, 0, RectSize.Width, RectSize.Height)
        e.Graphics.DrawRectangle(Pens.Green, Rect)

        ' PRINT STRING ROTATED 180 DEGREES
        e.Graphics.ResetTransform()
        e.Graphics.TranslateTransform(Tx, Ty)
        e.Graphics.RotateTransform(180)
        e.Graphics.DrawString("GDI+ Graphics (180)", fnt, _
                       Brushes.Black, 0, 0)
        RectSize = e.Graphics.MeasureString("GDI+ Graphics (180)", fnt)
        Rect = New Rectangle(0, 0, RectSize.Width, RectSize.Height)
        e.Graphics.DrawRectangle(Pens.Green, Rect)
    End Sub
End Class

⌨️ 快捷键说明

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