Restore Form To Previous Size

A

amyl

I have an application where users can minimize it to the systray. I
would like when the user restores the application from the systray to
return to the previous forms size.

If the form was maximized when minimized and I use the following code

this.WindowState = FormWindowState.Normal ;

the form is not resized back to its previous maximized state.

I figured I could grab the location and size of the form prior to
minimizing using
formXLocation = this.Location.X;
formYLocation = this.Location.Y;
formSizeWidth = this.Size.Width;
formSizeHeight = this.Size.Height;

However, I am not sure exactly how to force the form back to those
sizes since you can't call
this.Location.X = ... since Location.X is not a variable.

Thanks,
Amy
 
M

Marc Gravell

Rether than restoring to "normal", just store the old FormWindowState and
put that back (i.e. go back to maximised if you were previously maximised);
you might find that fixes it.
Alternatively, rather than storing x,y pairs and width, height pairs, store
the Point and Size values; the Location and Size properties are settable.

Marc
 
A

amyl

Marc said:
Rether than restoring to "normal", just store the old FormWindowState and
put that back (i.e. go back to maximised if you were previously maximised);

Thanks Marc - sotring the old windowstate did the trick.

Amy.
 
H

Herfried K. Wagner [MVP]

However, I am not sure exactly how to force the form back to those
sizes since you can't call
this.Location.X = ... since Location.X is not a variable.

\\\
this.Location = new Point(..., ...);
///
 

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