📄 form1.vb
字号:
Imports System.Drawing.Drawing2D
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
Protected Overrides Sub OnPaint(ByVal e As Windows.Forms.PaintEventArgs)
Dim g As Graphics = e.Graphics
'把客户区设置为白色
g.FillRectangle(Brushes.White, Me.ClientRectangle)
'定义相对于X轴镜像的转换矩阵,使得Y轴朝上
Dim mat As New Matrix(1, 0, 0, -1, 0, 0)
g.Transform = mat
'将坐标原点移动到屏幕中心
Dim rect As Rectangle = Me.ClientRectangle
Dim w As Integer = rect.Width
Dim h As Integer = rect.Height
g.TranslateTransform(w / 2, -h / 2)
'在全局坐标下绘制椭圆
g.DrawEllipse(Pens.Red, -100, -100, 200, 200)
g.FillRectangle(Brushes.Black, 100 - 2, 0 + 2, 4, 4)
g.DrawRectangle(Pens.Blue, 0 - 2, -100 + 2, 4, 4)
g.DrawRectangle(Pens.Blue, -100 - 2, 0 + 2, 4, 4)
g.DrawRectangle(Pens.Blue, 0 - 2, 100 + 2, 4, 4)
'创建一个椭圆,然后在局部坐标系中进行几何变换
Dim gp As New GraphicsPath()
gp.AddEllipse(-100, -100, 200, 200)
Dim mat2 As New Matrix()
'平移变换
mat2.Translate(150, 150)
'旋转变换,缺省时按顺时针方向旋转
mat2.Rotate(30)
gp.Transform(mat2)
g.DrawPath(Pens.Blue, gp)
Dim p() As PointF = gp.PathPoints()
g.FillRectangle(Brushes.Black, p(0).X - 2, p(0).Y + 2, 4, 4)
g.DrawRectangle(Pens.Blue, p(3).X - 2, p(3).Y + 2, 4, 4)
g.DrawRectangle(Pens.Blue, p(6).X - 2, p(6).Y + 2, 4, 4)
g.DrawRectangle(Pens.Blue, p(9).X - 2, p(9).Y + 2, 4, 4)
gp.Dispose()
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -