Restore Form To Previous Size

  • Thread starter Thread starter amyl
  • Start date Start date
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
 
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
 
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.
 
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(..., ...);
///
 
Back
Top