How do I draw a circular gradient?

核能气质少年 提交于 2020-01-21 03:46:09

问题


How do I draw a circular gradient like this in vb.net?


回答1:


Check out this great page. The code in the article is in C#. Here is a vb.net port of the code you'e 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.



来源:https://stackoverflow.com/questions/5392956/how-do-i-draw-a-circular-gradient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!