Click to See Complete Forum and Search --> : Save and Restore Form Position and State


HilemonC
April 23rd, 2003, 11:30 AM
This has to be simple, but it's giving me fits...

At start up, I want my main application form to remember its position, size, and state (normal, maximized, or minimized) from the previous execution. I have created event handlers for Closing and Load, and it almost works.

Here's the problem scenario: The application is in the maximized state when closed. At the next start up, the application is maximized, BUT when I click on the restore/normal box, the form remains full screen. The cause of this is that the form's Location and Size properties were changed when the maximize box was clicked during the first execution, and those values are what I output in my Closing handler.

I have found no reliable way to get the normal/restored position and size while in the Maximized state, and if I set the WindowState to Normal during the Close handler, the Size property is updated but not the Location. There is a member variable of Form called restoredWindowBounds. However, it is apparently Private because I cannot access it (other than in the debugger).

Any ideas? It feels like I'm making this WAY too hard.

Regards,
Chris Hilemon

Holiday
April 23rd, 2003, 03:57 PM
Do you store the location-point persitent?

HilemonC
April 24th, 2003, 07:55 AM
Yes, in my Closing event handler, I am storing the location and the size as well as the WindowState (Maximized, Minimized, or Normal) in an XML file. I load this same information in my Load event handler.

I believe that I could track the Normal location and size by adding my own member variables for these values and setting them in both Move and Resize event handlers. However, this seems to be a brute force, manual method for something that most applications need and therefore should be functionality provided by the Framework.

Like I said in my original post, the values are there (in the restoredWindowBounds member variable of the Form class). However, one can't get to them directly because this variable is apparently private, and I have found no method to get at this information indirectly.

pareshgh
April 24th, 2003, 06:01 PM
Only Handle the Resize Event , by this when ever that event is occored it just stores the location point, no matter what.


this way even it is maximized or restored or whatever doesn't matter, well you don't need to store the location in Closing events. since it is already stored.

check that out and see if it works for you,

-Paresh