📄 form1.vb
字号:
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 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents button1 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Pic1 As System.Windows.Forms.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.button1 = New System.Windows.Forms.Button()
Me.Pic1 = New System.Windows.Forms.PictureBox()
Me.Button2 = New System.Windows.Forms.Button()
Me.Button3 = New System.Windows.Forms.Button()
Me.Button4 = New System.Windows.Forms.Button()
Me.Button5 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'button1
'
Me.button1.Location = New System.Drawing.Point(392, 16)
Me.button1.Name = "button1"
Me.button1.Size = New System.Drawing.Size(128, 32)
Me.button1.TabIndex = 0
Me.button1.Text = "画线条和空心形状"
'
'Pic1
'
Me.Pic1.BackColor = System.Drawing.SystemColors.ActiveCaptionText
Me.Pic1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.Pic1.Location = New System.Drawing.Point(8, 16)
Me.Pic1.Name = "Pic1"
Me.Pic1.Size = New System.Drawing.Size(360, 360)
Me.Pic1.TabIndex = 1
Me.Pic1.TabStop = False
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(392, 88)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(128, 40)
Me.Button2.TabIndex = 2
Me.Button2.Text = "画实心区域"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(392, 168)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(128, 40)
Me.Button3.TabIndex = 3
Me.Button3.Text = "用复杂图案填充"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(392, 256)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(128, 40)
Me.Button4.TabIndex = 4
Me.Button4.Text = "输出文本"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(392, 320)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(128, 40)
Me.Button5.TabIndex = 5
Me.Button5.Text = "显示图象"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(528, 399)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button5, Me.Button4, Me.Button3, Me.Button2, Me.Pic1, Me.button1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button1.Click
'第一步
Dim g As Graphics = Pic1.CreateGraphics
g.Clear(Color.White)
'第二步
Dim myPen As New Pen(Color.Red)
myPen.Width = 2
'第三步
g.DrawLine(myPen, 1, 1, 45, 65) '绘制线条
myPen.Color = Color.Yellow
g.DrawBezier(myPen, 15, 15, 30, 30, 45, 30, 87, 20) '绘制贝塞尔样条
myPen.Color = Color.Aquamarine
g.DrawEllipse(myPen, New Rectangle(33, 45, 40, 50)) '绘制由边框定义的椭圆
myPen.Color = Color.Black
g.DrawPolygon(myPen, New PointF() {New PointF(1, 1), New PointF(20, 10), New PointF(5, 4), New PointF(100, 2), New PointF(200, 50), New PointF(39, 45)}) '绘制由一组 Point 结构定义的多边形。
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'第一步
Dim g As Graphics = Pic1.CreateGraphics
g.Clear(Color.White)
'第二步
Dim myBrush As New SolidBrush(Color.Red)
'第三步
g.FillPolygon(myBrush, New PointF() {New PointF(20, 20), New PointF(50, 100), New PointF(60, 10), New PointF(200, 4), New PointF(0, 0), New PointF(20, 20)}) '填充多边形区域
myBrush.Color = Color.Green
g.FillPie(myBrush, New Rectangle(50, 50, 300, 300), 0, 90) '填充扇形区的内部
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'第一步
Dim g As Graphics = Pic1.CreateGraphics
g.Clear(Color.White)
'第二步
Dim myBrush As New TextureBrush(New Bitmap("C:\myBitmap.bmp"))
'第三步
g.FillEllipse(myBrush, New Rectangle(45, 0, 200, 350)) '绘制椭圆。
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'第一步
Dim g As Graphics = Pic1.CreateGraphics
g.Clear(Color.White)
'第二步
Dim mybrush As New Drawing2D.LinearGradientBrush(ClientRectangle, Color.Red, Color.Yellow, Drawing2D.LinearGradientMode.Horizontal)
'第三步
Dim myFont As New Font("Times New Roman", 24)
'第四步
g.DrawString("Look at this text!", myFont, myBrush, New RectangleF(10, 10, 100, 200)) '由于提供了 RectangleF 对象,所以文本将在矩形中换行
'g.DrawString("Look at this text!", myFont, myBrush, 10, 10) '没有提供RectangleF 对象,文本将从起始坐标处开始显示
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'第一步
Dim myBitmap As New Bitmap("C:\myBitmap.bmp")
'第二步
Dim g As Graphics = Pic1.CreateGraphics
'第三步
g.DrawImage(myBitmap, 1, 1)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -