Dim pgb As New PathGradientBrush(New Point() { _
New Point(0, 0), _
New Point(0, Me.ClientRectangle.Height), _
New Point(Me.ClientRectangle.Width, Me.ClientRectangle.Height), _
New Point(Me.ClientRectangle.Width, 0)})
pgb.SurroundColors = New Color() {Color.Red}
pgb.CenterColor = Color.Gray
e.Graphics.FillRectangle(pgb, Me.ClientRectangle)
pgb.Dispose()
这是另一个可能的解决方案:
Dim pth As New GraphicsPath()
pth.AddEllipse(Me.ClientRectangle)
Dim pgb As New PathGradientBrush(pth)
pgb.SurroundColors = New Color() {Color.Red}
pgb.CenterColor = Color.Gray
e.Graphics.FillRectangle(pgb, Me.ClientRectangle)
Check out this great page. The code in the article is in C#. Here is a VB.NET port of the code you're interested in and updated for a rectangular fill (based on the article's triangle fill sample):
Dim pgb As New PathGradientBrush(New Point() { _
New Point(0, 0), _
New Point(0, Me.ClientRectangle.Height), _
New Point(Me.ClientRectangle.Width, Me.ClientRectangle.Height), _
New Point(Me.ClientRectangle.Width, 0)})
pgb.SurroundColors = New Color() {Color.Red}
pgb.CenterColor = Color.Gray
e.Graphics.FillRectangle(pgb, Me.ClientRectangle)
pgb.Dispose()
Here's another possible solution:
Dim pth As New GraphicsPath()
pth.AddEllipse(Me.ClientRectangle)
Dim pgb As New PathGradientBrush(pth)
pgb.SurroundColors = New Color() {Color.Red}
pgb.CenterColor = Color.Gray
e.Graphics.FillRectangle(pgb, Me.ClientRectangle)
Note that this last code snippet will draw a circle bounded inside of a rectangle. If you want the circular gradient to fill the entire rectangle you'll have to calculate a larger elliptic path with a larger rectangle.
发布评论
评论(1)
请查看这个精彩页面。文章中的代码是 C# 语言。下面是您感兴趣的代码的 VB.NET 端口,并针对矩形填充进行了更新(基于本文的三角形填充示例):
这是另一个可能的解决方案:
请注意,最后一个代码片段将绘制一个边界在长方形。如果您希望圆形渐变填充整个矩形,则必须使用更大的矩形计算更大的椭圆路径。
Check out this great page. The code in the article is in C#. Here is a VB.NET port of the code you're interested in and updated for a rectangular fill (based on the article's triangle fill sample):
Here's another possible solution:
Note that this last code snippet will draw a circle bounded inside of a rectangle. If you want the circular gradient to fill the entire rectangle you'll have to calculate a larger elliptic path with a larger rectangle.