📄 form1.vb
字号:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
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 PictureBox1 As System.Windows.Forms.PictureBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Button7 As System.Windows.Forms.Button
Friend WithEvents Button8 As System.Windows.Forms.Button
Friend WithEvents Button9 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.PictureBox1 = New System.Windows.Forms.PictureBox
Me.Button1 = New System.Windows.Forms.Button
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.Button6 = New System.Windows.Forms.Button
Me.Button7 = New System.Windows.Forms.Button
Me.Button8 = New System.Windows.Forms.Button
Me.Button9 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'PictureBox1
'
Me.PictureBox1.BackColor = System.Drawing.SystemColors.Window
Me.PictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
Me.PictureBox1.Dock = System.Windows.Forms.DockStyle.Left
Me.PictureBox1.Location = New System.Drawing.Point(0, 0)
Me.PictureBox1.Name = "PictureBox1"
Me.PictureBox1.Size = New System.Drawing.Size(208, 266)
Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize
Me.PictureBox1.TabIndex = 0
Me.PictureBox1.TabStop = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(240, 8)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(56, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "点"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(240, 48)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(56, 24)
Me.Button2.TabIndex = 2
Me.Button2.Text = "直 线"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(240, 88)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(56, 24)
Me.Button3.TabIndex = 3
Me.Button3.Text = "椭 圆"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(240, 128)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(56, 24)
Me.Button4.TabIndex = 4
Me.Button4.Text = "弧 形"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(240, 168)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(56, 24)
Me.Button5.TabIndex = 5
Me.Button5.Text = "扇 形"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(240, 208)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(56, 24)
Me.Button6.TabIndex = 6
Me.Button6.Text = "矩 形"
'
'Button7
'
Me.Button7.Location = New System.Drawing.Point(312, 8)
Me.Button7.Name = "Button7"
Me.Button7.Size = New System.Drawing.Size(56, 24)
Me.Button7.TabIndex = 7
Me.Button7.Text = "三角形"
'
'Button8
'
Me.Button8.Location = New System.Drawing.Point(312, 48)
Me.Button8.Name = "Button8"
Me.Button8.Size = New System.Drawing.Size(56, 24)
Me.Button8.TabIndex = 8
Me.Button8.Text = "多边形"
'
'Button9
'
Me.Button9.Location = New System.Drawing.Point(312, 88)
Me.Button9.Name = "Button9"
Me.Button9.Size = New System.Drawing.Size(56, 24)
Me.Button9.TabIndex = 9
Me.Button9.Text = "贝塞尔"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(376, 246)
Me.Controls.Add(Me.Button9)
Me.Controls.Add(Me.Button8)
Me.Controls.Add(Me.Button7)
Me.Controls.Add(Me.Button6)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.PictureBox1)
Me.Name = "Form1"
Me.Text = "线图"
Me.ResumeLayout(False)
End Sub
#End Region
Dim g As System.Drawing.Graphics
Dim pen1 As New System.Drawing.Pen(Color.Red, 3)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PictureBox1.Refresh()
g = PictureBox1.CreateGraphics
Dim point1 As System.Drawing.Point
Dim point2 As System.Drawing.Point
Dim i, x, y, bx, by, x0, y0, n, r As Short
Const pi = 3.1415926
Dim a As Single
n = 3
r = 20
For x = 60 To 450 Step 60
For y = 20 To 350 Step 60
If n = 11 Then
n = 5
Else
n = n + 2
End If
For a = 0 To 4 * pi Step 4 * pi / n
x0 = x + r * System.Math.Sin(a)
y0 = y - r * System.Math.Cos(a)
If a = 0 Then
point1.x = x0 : point1.y = y0 : bx = x0 : by = y0
Else
point2.X = x0 : point2.Y = y0
g.DrawLine(pen1, point1, point2)
point1 = point2
End If
Next
g.DrawLine(pen1, point1, point2)
Next
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
g = PictureBox1.CreateGraphics
g.DrawLine(pen1, 20, 20, 160, 160)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
g = PictureBox1.CreateGraphics
g.DrawEllipse(pen1, 50, 50, 100, 150)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
g = PictureBox1.CreateGraphics
g.DrawArc(pen1, 90, 50, 100, 150, 150, 160)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
g = PictureBox1.CreateGraphics
g.DrawPie(pen1, 50, 50, 150, 150, 0, 170)
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
g = PictureBox1.CreateGraphics
g.DrawRectangle(pen1, 30, 30, 50, 60)
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim p(3) As System.Drawing.Point
p(0).X = 0
p(0).Y = 0
p(1).X = 40
p(1).Y = 120
p(2).X = 110
p(2).Y = 70
g = PictureBox1.CreateGraphics
g.DrawPolygon(pen1, p)
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Dim p(5) As System.Drawing.Point
p(0).X = 0
p(0).Y = 0
p(1).X = 40
p(1).Y = 120
p(2).X = 110
p(2).Y = 70
p(3).X = 30
p(3).Y = 30
p(4).X = 170
p(4).Y = 10
g = PictureBox1.CreateGraphics
g.DrawPolygon(pen1, p)
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
g = PictureBox1.CreateGraphics
g.DrawBezier(pen1, 10, 20, 140, 150, 100, 30, 150, 200)
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -