Windows Application Error: Rectangle cannot have a width or height equal to 0

Last Reply 3 months ago By dharmendr

Posted 3 months ago

Error Rectangle '{X=0,Y=0,Width=0,Height=0}' cannot have a width or height equal to 0.

class Gradient : Panel
{
    public Color ColorTop { get; set; }
    public Color ColorBottom { get; set; }

    protected override void OnPaint(PaintEventArgs e)
    {
        LinearGradientBrush lgb = new LinearGradientBrush(this.ClientRectangle, this.ColorTop, this.ColorBottom, 90F);
        Graphics g = e.Graphics;
        g.FillRectangle(lgb, this.ClientRectangle);
        base.OnPaint(e);
    }
}
You are viewing reply posted by: dharmendr 3 months ago.
Posted 3 months ago

Hi anirudhp,

Rectangle with zero width and zero height makes no sense and not allowed where you tried to use it.

Use some reasonable Width and Height.