📄 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()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackColor = System.Drawing.Color.White
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
Dim g As Graphics = e.Graphics
'定义一个线性梯度刷
Dim lGBrush As New LinearGradientBrush( _
New Point(0, 10), _
New Point(150, 10), _
Color.FromArgb(255, 255, 0, 0), _
Color.FromArgb(255, 0, 255, 0))
Dim pen As New Pen(lGBrush)
'用线性梯度刷效果的笔绘制一条直线段,填充一个矩形
g.DrawLine(pen, 10, 130, 500, 130)
g.FillRectangle(lGBrush, 50, 150, 370, 30)
'定义路径并添加一个椭圆
Dim gp As New GraphicsPath()
gp.AddEllipse(10, 10, 200, 100)
'用该路径定义路径梯度刷
Dim brush As New PathGradientBrush(gp)
'颜色数组
Dim colors As Color() = { _
Color.FromArgb(255, 255, 0, 0), _
Color.FromArgb(255, 100, 100, 100), _
Color.FromArgb(255, 0, 255, 0), _
Color.FromArgb(255, 0, 0, 255)}
' 定义颜色渐变比率
Dim r As Single() = { _
0.0F, _
0.3F, _
0.6F, _
1.0F}
Dim blend As New ColorBlend()
blend.Colors = colors
blend.Positions = r
brush.InterpolationColors = blend
'在椭圆外填充一个矩形
g.FillRectangle(brush, 0, 0, 210, 110)
'用添加了椭圆的路径定义第二个路径梯度刷
Dim gp2 As New GraphicsPath()
gp2.AddEllipse(300, 0, 200, 100)
Dim brush2 As New PathGradientBrush(gp2)
' 设置中心点的位置和颜色
brush2.CenterPoint = New PointF(450, 50)
brush2.CenterColor = Color.FromArgb(255, 0, 255, 0)
'设置边界颜色
Dim colors2 As Color() = {Color.FromArgb(255, 255, 0, 0)}
brush2.SurroundColors = colors2
'用第二个梯度刷填充椭圆
g.FillEllipse(brush2, 300, 0, 200, 100)
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 + -