How to save window size when form is minimized?

J

Jeff Connelly

C#. If I minimize a window programmatically (form.WindowState =
System.Windows.Forms.FormWindowState.Minimized), and then restore it
programmitically (FormWindowState.Normal) I can see in the debugger that the
form.Size changes both times. So where is that size saved away?

What I need to do is persist the state of forms between executions of the
application. So I save the form size and state. I The problem is, if the
state is minimized, then the size will always be "0" (the size of a
minimized form). If I recreate the form when I start the app again, it
starts minimized. If I then restore the (manually, not programmatically),
it no longer knows what size to go back to. It stays the same size as the
minimized size, but the buttons just change (you can no longer restore - it
is already restored to that mini-size). You can resize the form manually at
this point.
 
H

Herfried K. Wagner [MVP]

Jeff Connelly said:
C#. If I minimize a window programmatically (form.WindowState =
System.Windows.Forms.FormWindowState.Minimized), and then restore it
programmitically (FormWindowState.Normal) I can see in the debugger that
the form.Size changes both times. So where is that size saved away?

What I need to do is persist the state of forms between executions of the
application.

Save and restore Form position and layout with this component
<URL:http://www.codeproject.com/cs/miscctrl/RealPosition.asp>

Form Placement Component
<URL:http://www.codeproject.com/csharp/Placement.asp>
 
J

Jeff Connelly

Herfried K. Wagner said:
Save and restore Form position and layout with this component
<URL:http://www.codeproject.com/cs/miscctrl/RealPosition.asp>

Thank you for the link. I looked at his source code, and it appears he has
not solved this problem either. To wit:
f.WindowState = (FormWindowState)windowState;
// do not allow minimized restore
if (f.WindowState == FormWindowState.Minimized)
f.WindowState = FormWindowState.Normal;

I specifically do want to "allow minimized restore".
 
J

Jeff Connelly

Herfried K. Wagner said:
Take a look at the second article.

Bingo! Thanks for "persisting" with that second link (a little programmer
humor there.) That was exactly what I needed. I can't believe .NET doesn't
have this!
 

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