One of my user reported a strange issue for a C# Windows Forms MDI application.
When the application closes, I save the WindowState, and the Bouds or RestoreBounds when the form is either Maximized or Minimized.
When the application restarts, I rehydrate the forms exactly like they were when the application closed.
My issue is that if a form is Minimized, I set its bound and then set the WindowState to Minimized. It is working great until there. But when the user tries to restore to the previous size, the window is correctly set to the previous top/left but width and height are not following correctly.
The strange thing is that the behavior works properly with the Maximized state!
Any ideas on how to ensure a from can be restored correctly?
Here is some code from my OnLoad override (Bounds are properly persisted):
I've encountered this problem before. The actual dimensions of the window are not guaranteed to be correctly reported if the window is in a maximized or minimized state. You should introduce logic that does not store the bounds if the windowstate is other than Normal.
Éric Moreau
ASKER
This is exactly why I use RestoreBounds!
Russ Suter
... which apparently isn't working for you. As I said, I've encountered this problem before. The solution that worked for me was to only store bounds when the window state was normal. Perhaps you could post your complete sample. I'd be happy to work with you to find the answer.