PathGradient code almost works -
05-07-2007
, 10:01 AM
Just playing to become familiar with the PathGradient, I wrote this to
display two squares. The first one displays but not the second one.
I made some guesses about reusing the Path, and the Point and Colors
arrays - probable not all correct.
Thanks
Private Sub FillGradientRectangles()
Dim gr As Graphics = Panel1.CreateGraphics
Dim path As New GraphicsPath()
Dim points As Point() = { _
New Point(0, 0), _
New Point(0, 150), _
New Point(150, 150), _
New Point(150, 0)}
path.AddLines(points)
Dim pthGrBrush As New PathGradientBrush(path)
pthGrBrush.CenterColor = Color.FromArgb(255, 0, 127, 127)
Dim colors As Color() = { _
Color.FromArgb(255, 0, 0, 0), _
Color.FromArgb(255, 0, 255, 0), _
Color.FromArgb(255, 0, 255, 255), _
Color.FromArgb(255, 0, 0, 255)}
pthGrBrush.SurroundColors = colors
gr.FillPath(pthGrBrush, path)
'DRAW SECOND SQUARE
path.Reset()
points(0) = New Point(300, 0)
points(1) = New Point(300, 150)
points(2) = New Point(150, 150)
points(3) = New Point(150, 0)
path.AddLines(points)
pthGrBrush.CenterColor = Color.FromArgb(255, 127, 127, 127)
colors(0) = Color.FromArgb(255, 255, 0, 0)
colors(1) = Color.FromArgb(255, 255, 255, 0)
colors(2) = Color.FromArgb(255, 0, 255, 255)
colors(3) = Color.FromArgb(255, 0, 0, 255)
pthGrBrush.SurroundColors = colors
gr.FillPath(pthGrBrush, path)
gr.Dispose()
End Sub |