gpt4 book ai didi

vb.net - 如何绘制圆形渐变?

转载 作者:行者123 更新时间:2023-12-04 00:47:47 26 4
gpt4 key购买 nike

如何绘制圆形渐变 like this在 vb.net 中?

A Red Circular Gradient

最佳答案

看看这个 great page .文章中的代码是用 C# 编写的。这是您感兴趣的代码的 VB.NET 端口,并针对矩形填充进行了更新(基于文章的三角形填充示例):

    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)

请注意,最后一个代码片段将在矩形内部绘制一个圆圈。如果您希望圆形渐变填充整个矩形,您必须计算一个更大的椭圆路径和更大的矩形。

关于vb.net - 如何绘制圆形渐变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5392956/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com