G
Guest
I'm trying to draw a linear gradient between two colours using the
LinearGradientBrush class. It sounds simple enough however I get a line of
the second colour at the top of the gradient in certain situations. Placing
the code below in the paint event of a Panel will hopefully demonstrate the
problem:
System.Drawing.Rectangle rect = new Rectangle(0, 10, 100, 60);
using (System.Drawing.Drawing2D.LinearGradientBrush brush = new
System.Drawing.Drawing2D.LinearGradientBrush(rect,
System.Drawing.Color.Yellow, System.Drawing.Color.Red, 90, false))
{
e.Graphics.FillRectangle(brush, rect);
}
The problem only seems to occur when the Y position of the rectangle is
greater than 0, and at random values for the height. The above example works
correctly when the rectangle is (0, 0, 100, 60) or (0, 10, 100, 20). I've
tried this in VS2003 and VS2005 with the same results. Also I've tested this
on five computers and it works on one but the line appears on the others.
Has anyone else seen this problem or have any thoughts on how to avoid it?
Thanks
LinearGradientBrush class. It sounds simple enough however I get a line of
the second colour at the top of the gradient in certain situations. Placing
the code below in the paint event of a Panel will hopefully demonstrate the
problem:
System.Drawing.Rectangle rect = new Rectangle(0, 10, 100, 60);
using (System.Drawing.Drawing2D.LinearGradientBrush brush = new
System.Drawing.Drawing2D.LinearGradientBrush(rect,
System.Drawing.Color.Yellow, System.Drawing.Color.Red, 90, false))
{
e.Graphics.FillRectangle(brush, rect);
}
The problem only seems to occur when the Y position of the rectangle is
greater than 0, and at random values for the height. The above example works
correctly when the rectangle is (0, 0, 100, 60) or (0, 10, 100, 20). I've
tried this in VS2003 and VS2005 with the same results. Also I've tested this
on five computers and it works on one but the line appears on the others.
Has anyone else seen this problem or have any thoughts on how to avoid it?
Thanks