📄 form1.vb
字号:
Imports System.drawing
Imports System.Drawing.Drawing2D
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 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(392, 323)
Me.Name = "Form1"
Me.Text = "使用Brush对象"
End Sub
#End Region
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
'获取Graphics对象
Dim g As Graphics = e.Graphics
Dim bgBrush As System.Drawing.Brush
'定义Image对象
Dim bgImage As Image
'从硬盘上获取某路径下的BMP格式图片
'当然首先要求你所指定的位置下存在这个文件
bgImage = New Bitmap("..\BackImage.bmp")
'使用该图片创建一个纹理刷子,用于绘制背景
bgBrush = New TextureBrush(bgImage)
g.FillRectangle(bgBrush, ClientRectangle)
Dim bg2Brush As Brush
bg2Brush = New SolidBrush(Color.FromArgb(100, Color.Red))
g.FillRectangle(bg2Brush, ClientRectangle)
'创建一个阴影刷子,并用它填充一个圆
Dim hb As HatchBrush = New HatchBrush(HatchStyle.Shingle, Color.Red, Color.FromArgb(100, Color.Yellow))
g.FillEllipse(hb, 200, 10, 150, 150)
'创建一个GraphicsPath对象需要两个参数
'第一个是一个Point数组,表示图形的顶点
'第二个是一个Byte数组,表示各边的类型
Dim path As GraphicsPath
path = New GraphicsPath(New Point() {New Point(80, 40), New Point(300, 100), New Point(100, 100), New Point(200, 250), New Point(20, 280), New Point(20, 150)}, _
New Byte() {CType(PathPointType.Start, Byte), CType(PathPointType.Bezier, Byte), CType(PathPointType.Bezier, Byte), CType(PathPointType.Bezier, Byte), CType(PathPointType.Line, Byte), CType(PathPointType.Line, Byte)})
'使用该GraphicsPath对象创建一个PathGradientBrush刷子
Dim pgb As PathGradientBrush = New PathGradientBrush(path)
'CenterColor表示图形中心的颜色
pgb.CenterColor = Color.Gold
'SurroundColors表示图形周围的颜色,是一个Color数组
pgb.SurroundColors = New Color() {Color.Green, Color.Yellow, Color.Red, Color.Blue, Color.Orange, Color.Violet}
'填充
g.FillPath(pgb, path)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -