Groups | Blog | Home
all groups > dotnet drawing api > october 2003 >

dotnet drawing api : LinearGradientBrush bug?


Edward J. Stembler
10/6/2003 12:37:19 PM
I'm using a LinearGradientBrush when drawing on a
resizeable (dock = client etc) panel canvas and I've
noticed a strange side effect... the gradient brush (or
something else?) draws a solid line using the second
color as the first line. This behavior should not occur,
and does not occur if the panel is not resizable.

Here's some code to play with, make sure the form is
resizeable and the panel is docked to the client:


private void panel1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
int w = panel1.Width;
int h = panel1.Height;

// Fill the background with Window
e.Graphics.FillRectangle(SystemBrushes.Window, 0, 0,
w, h);

// Fill the right corner gradient
Color c1 = SystemColors.Window;
Color c2 = SystemColors.InactiveCaptionText;

int gw = w / 2;
int gx = w - gw;
const int gy = 0;

Rectangle area = new Rectangle(gx, gy, gw, h);
LinearGradientBrush br = new LinearGradientBrush
(area, c1, c2, LinearGradientMode.Horizontal);

e.Graphics.FillRectangle(br, area);
}

private void panel1_Resize(object sender,
System.EventArgs e)
{
panel1.Invalidate();
}

Edward J. Stembler
10/6/2003 12:55:30 PM
Nevermind.

I fixed it by setting the WrapMode to TileFlipX.

i.e.:
br.WrapMode = WrapMode.TileFlipX;

I still think the default behavior is a bug though.

[quoted text, click to view]
AddThis Social Bookmark Button