简体   繁体   中英

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 im 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

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(ie Height and Width not equal to zero).

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM