📄 form1.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 PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents bttnDrawShape As System.Windows.Forms.Button
Friend WithEvents bttnTranslate As System.Windows.Forms.Button
Friend WithEvents bttnRotate As System.Windows.Forms.Button
Friend WithEvents bttnTranslateRotate As System.Windows.Forms.Button
Friend WithEvents bttnScale As System.Windows.Forms.Button
Friend WithEvents bttnScaleRotate As System.Windows.Forms.Button
Friend WithEvents bttnScaleRotateTranslate As System.Windows.Forms.Button
Friend WithEvents bttnRotateTranslate As System.Windows.Forms.Button
Friend WithEvents bttnClear As System.Windows.Forms.Button
'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()
Me.bttnScale = New System.Windows.Forms.Button()
Me.bttnRotate = New System.Windows.Forms.Button()
Me.PictureBox1 = New System.Windows.Forms.PictureBox()
Me.bttnDrawShape = New System.Windows.Forms.Button()
Me.bttnTranslate = New System.Windows.Forms.Button()
Me.bttnRotateTranslate = New System.Windows.Forms.Button()
Me.bttnTranslateRotate = New System.Windows.Forms.Button()
Me.bttnScaleRotateTranslate = New System.Windows.Forms.Button()
Me.bttnScaleRotate = New System.Windows.Forms.Button()
Me.bttnClear = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'bttnScale
'
Me.bttnScale.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnScale.Location = New System.Drawing.Point(528, 196)
Me.bttnScale.Name = "bttnScale"
Me.bttnScale.Size = New System.Drawing.Size(152, 40)
Me.bttnScale.TabIndex = 5
Me.bttnScale.Text = "Scale Shape"
'
'bttnRotate
'
Me.bttnRotate.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnRotate.Location = New System.Drawing.Point(528, 149)
Me.bttnRotate.Name = "bttnRotate"
Me.bttnRotate.Size = New System.Drawing.Size(152, 40)
Me.bttnRotate.TabIndex = 3
Me.bttnRotate.Text = "Rotate Shape"
'
'PictureBox1
'
Me.PictureBox1.BackColor = System.Drawing.SystemColors.HighlightText
Me.PictureBox1.Location = New System.Drawing.Point(8, 8)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(512, 416)
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'bttnDrawShape
'
Me.bttnDrawShape.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnDrawShape.Location = New System.Drawing.Point(528, 55)
Me.bttnDrawShape.Name = "bttnDrawShape"
Me.bttnDrawShape.Size = New System.Drawing.Size(152, 40)
Me.bttnDrawShape.TabIndex = 1
Me.bttnDrawShape.Text = "Draw Shape"
'
'bttnTranslate
'
Me.bttnTranslate.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnTranslate.Location = New System.Drawing.Point(528, 102)
Me.bttnTranslate.Name = "bttnTranslate"
Me.bttnTranslate.Size = New System.Drawing.Size(152, 40)
Me.bttnTranslate.TabIndex = 2
Me.bttnTranslate.Text = "Translate Shape"
'
'bttnRotateTranslate
'
Me.bttnRotateTranslate.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte))
Me.bttnRotateTranslate.Location = New System.Drawing.Point(528, 290)
Me.bttnRotateTranslate.Name = "bttnRotateTranslate"
Me.bttnRotateTranslate.Size = New System.Drawing.Size(152, 40)
Me.bttnRotateTranslate.TabIndex = 6
Me.bttnRotateTranslate.Text = "Rotate and Translate Shape"
'
'bttnTranslateRotate
'
Me.bttnTranslateRotate.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.bttnTranslateRotate.Location = New System.Drawing.Point(528, 243)
Me.bttnTranslateRotate.Name = "bttnTranslateRotate"
Me.bttnTranslateRotate.Size = New System.Drawing.Size(152, 40)
Me.bttnTranslateRotate.TabIndex = 4
Me.bttnTranslateRotate.Text = "Translate and Rotate Shape"
'
'bttnScaleRotateTranslate
'
Me.bttnScaleRotateTranslate.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte))
Me.bttnScaleRotateTranslate.Location = New System.Drawing.Point(528, 384)
Me.bttnScaleRotateTranslate.Name = "bttnScaleRotateTranslate"
Me.bttnScaleRotateTranslate.Size = New System.Drawing.Size(152, 40)
Me.bttnScaleRotateTranslate.TabIndex = 6
Me.bttnScaleRotateTranslate.Text = "Scale Rotate and Translate Shape"
'
'bttnScaleRotate
'
Me.bttnScaleRotate.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte))
Me.bttnScaleRotate.Location = New System.Drawing.Point(528, 337)
Me.bttnScaleRotate.Name = "bttnScaleRotate"
Me.bttnScaleRotate.Size = New System.Drawing.Size(152, 40)
Me.bttnScaleRotate.TabIndex = 6
Me.bttnScaleRotate.Text = "Scale and Rotate Shape"
'
'bttnClear
'
Me.bttnClear.Font = New System.Drawing.Font("Verdana", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(161, Byte))
Me.bttnClear.Location = New System.Drawing.Point(528, 8)
Me.bttnClear.Name = "bttnClear"
Me.bttnClear.Size = New System.Drawing.Size(152, 40)
Me.bttnClear.TabIndex = 6
Me.bttnClear.Text = "Clear"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(688, 437)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.bttnClear, Me.bttnRotateTranslate, Me.bttnScaleRotateTranslate, Me.bttnScaleRotate, Me.bttnScale, Me.bttnTranslateRotate, Me.bttnRotate, Me.bttnTranslate, Me.bttnDrawShape, Me.PictureBox1})
Me.Name = "Form1"
Me.Text = "Transformations Demo"
Me.ResumeLayout(False)
End Sub
#End Region
Dim G As Graphics
Dim bmp As Bitmap
Private Sub bttnDrawShape_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnDrawShape.Click
G.ResetTransform()
DrawShape(G)
End Sub
Private Sub bttnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnTranslate.Click
G.ResetTransform()
G.TranslateTransform(200, 90)
DrawShape(G)
End Sub
Private Sub bttnRotate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnRotate.Click
G.ResetTransform()
G.RotateTransform(45)
DrawShape(G)
End Sub
Private Sub bttnTranslateRotate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnTranslateRotate.Click
G.ResetTransform()
G.TranslateTransform(200, 90)
G.RotateTransform(45)
DrawShape(G)
End Sub
Private Sub bttnScale_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnScale.Click
G.ResetTransform()
G.ScaleTransform(0.8, 0.4)
DrawShape(G)
End Sub
Private Sub bttnScaleRotate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnScaleRotate.Click
G.ResetTransform()
G.RotateTransform(45)
G.ScaleTransform(0.5, 0.5)
DrawShape(G)
End Sub
Private Sub bttnScaleRotateTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnScaleRotateTranslate.Click
G.ResetTransform()
G.TranslateTransform(200, 90)
G.RotateTransform(45)
G.ScaleTransform(0.5, 0.5)
DrawShape(G)
End Sub
Private Sub bttnRotateTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnRotateTranslate.Click
G.ResetTransform()
G.RotateTransform(45)
G.TranslateTransform(200, 90)
DrawShape(G)
End Sub
Sub DrawShape(ByVal GraphicObject As Graphics)
Dim Font As Font = New Font("Comic Sans MS", 36, FontStyle.Bold, GraphicsUnit.Pixel)
Dim Pen As Pen = New Pen(Color.Red, 2)
GraphicObject.DrawRectangle(Pen, New Rectangle(1, 1, 200, 120))
GraphicObject.DrawRectangle(Pen, New Rectangle(1, 1, 200, 120))
GraphicObject.DrawString("VB.NET", Font, Brushes.Violet, 25, 5)
GraphicObject.DrawImage(Image.FromFile("..\Butterfly.jpg"), New PointF(50, 50))
PictureBox1.Refresh()
End Sub
Private Sub bttnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttnClear.Click
G.Clear(Color.White)
PictureBox1.Refresh()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
bmp = New Bitmap(PictureBox1.Width, PictureBox1.Height)
G = Graphics.FromImage(bmp)
PictureBox1.Image = bmp
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -