tags:

views:

170

answers:

3

I have a windows application and I want to save the size, position and WindowState between sessions. There is one caveat however. If the state when closing is minimized then I want to restore to the last visible state, i.e. Normal if it was normal before being minimized or maximized if it was maximized.

Is there a property, check, call do do this?

+1  A: 

Here's an example on form persistance and saving window state between sessions.

As for saving the state prior to window being minimized, that's something that you need to handle yourself by 'remembering' last two window states, there's no property/event that can do that for you.

Abbas
+2  A: 

You could use application settings (user scope) and when the Form_Closing event is triggered on your form, you can choose how to modify the settings before you save them with Properties.Settings.Default.Save();

ChronoPositron
A: 

You can "remember" the restored position before minimizing/maximizing.

You can restore the window before saving the position, this has the disadvantage of making your window blink before closing.

Or you can call the Win32 function GetWindowPlacment via InterOp, it returns the restored rectangle.

Nir