WatsMyName
WatsMyName

Reputation: 4478

C# Exception when window restored via taskbar click

I have a main form, frmMain. Everything is fine but whenever I minimize this window and then restore it clicking on taskbar,the exception is thrown.

Exception:

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

is thrown at Program.cs on line

Application.Run(new frmMain());

As i m new in C# I m not being able to solve this issue. Any help is highly appreciated.

EDIT I haven't use custom paintings, also havent used anything to deal with windows height or width programatically

Thanks

Upvotes: 0

Views: 581

Answers (3)

WatsMyName
WatsMyName

Reputation: 4478

To avoid further attention, and thinking would be helpful if someone find this post.

The culprit was custom control, which had dock property to "fill". I removed this control and instead used another default control and the problem is gone.

Thanks everyone for the help.

Upvotes: 0

Sriram Sakthivel
Sriram Sakthivel

Reputation: 73472

I assume you're using custom painting, which uses some kind of LinearGradientBrush or something like that. That would throw ArgumentException saying

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

For instance following code will reproduce the problem.

Rectangle r = new Rectangle(0, 0, 0, 0);
var b = new System.Drawing.Drawing2D.LinearGradientBrush(r, Color.AliceBlue, Color.AntiqueWhite, 90);

So you need to make sure your rectangle's Size is not empty(i.e Height and Width not equal to zero).

Upvotes: 3

Erdogan Kurtur
Erdogan Kurtur

Reputation: 3685

I believe you store your form position somewhere so when run again you can restore your position. Store on FormClosing event and read it only once.

Upvotes: 0

Related Questions