Gradient brush and circle not filling like I would expect

Blake81

Well-known member
Joined
Feb 23, 2006
Messages
304
Location
Georgia, USA
Programming Experience
1-3
I made an analog clock in GDI and I am trying to fill a circle in the center using a gradient brush to cover up the fact that the clock hands don't meet exactly in the same place. I'm noticing a strange effect on the right side of the circle when I do this. Could someone look at my code and tell me if they can see where the problem is? Thanks.

myclock.jpg


VB.NET:
Public Sub draw(ByVal imgDraw As Graphics)
        Dim x As New Drawing.Drawing2D.PathGradientBrush(Path)
        Dim mycolor(3) As Color
        If filled Then
            mycolor.SetValue(Color.Black, 0)
            mycolor.SetValue(Color.Gold, 1)
            mycolor.SetValue(Color.Black, 2)
            x.CenterColor = Color.White
            x.SurroundColors = mycolor
            imgDraw.FillPath(x, Path)
            imgDraw.DrawPath(Pens.Black, Path)
        ElseIf secfilled Then
            imgDraw.DrawPath(New Pen(Color.Red, 2), Path)
        End If
        mycolor.SetValue(Color.Black, 0)
        mycolor.SetValue(Color.Gold, 1)
        mycolor.SetValue(Color.Black, 2)
        Dim cpath As New Drawing2D.GraphicsPath()
        Dim cpoint As Point
        cpoint.X = 130
        cpoint.Y = 130
        Dim rect As Rectangle
        rect.Location = cpoint
        rect.Width = 35
        rect.Height = 35
        cpath.AddEllipse(cpoint.X, cpoint.Y, rect.Width, rect.Height)
        cpath.FillMode = Drawing2D.FillMode.Alternate
        Dim cgrad As New Drawing.Drawing2D.PathGradientBrush(cpath)
        cgrad.CenterColor = Color.Black
        Dim mycolortwo(3) As Color
        mycolortwo.SetValue(Color.Black, 0)
        mycolortwo.SetValue(Color.Gold, 1)
        mycolortwo.SetValue(Color.Black, 2)
        cgrad.SurroundColors = mycolortwo
        imgDraw.DrawEllipse(Pens.Black, rect)
        imgDraw.FillEllipse(cgrad, cpoint.X, cpoint.Y, rect.Width, rect.Height)
    End Sub
 
Yea, it's because if yuo use more than 1 color in the surround colors you get that result. Use the interpolation colors property and set a custom blend for the surround colors if you want multiple colors.
 
Back
Top