Rectangle/OnPaint Error in 2005

R

Ryan

Why do I sometimes get this error; works fine most of the time:
Rectangle '{X=0,Y=0,Width=0,Height=0}' cannot have a width or height equal
to 0


void OnPaint(Object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle r = ClientRectangle;
LinearGradientBrush gradientBrush = new LinearGradientBrush(r,
Color.Navy, Color.Chocolate, LinearGradientMode.ForwardDiagonal);
g.FillRectangle(gradientBrush, r);
}
 
R

Ryan

Peter,
The following line produces the error

LinearGradientBrush gradientBrush = new LinearGradientBrush(r, Color.Navy,
Color.Chocolate, LinearGradientMode.ForwardDiagonal);

Complete code:

void OnPaint(Object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle r = ClientRectangle;
LinearGradientBrush gradientBrush = new LinearGradientBrush(r,
Color.Navy, Color.Chocolate, LinearGradientMode.ForwardDiagonal);
g.FillRectangle(gradientBrush, r);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top