1

I have an application that is starting minimized.

I can set RestoreBounds to set to which size will the window restore when user restores it.

But how can I set if the form should restore to maximized or normal state? Normal is by default. I wish there was something like RestoreWindowState.

Can I do this using API somehow?

Jiri
  • 264
  • 4
  • 17

2 Answers2

1

From my experience, Window.RestoreBounds will always give you the final "normal" dimensions of your window, and Window.WindowState will always give you the final state of the window (max, min, normal). No matter what state you're in, you can always just save off RestoreBounds and WindowState and manually set the window dimensions/state.

This is how I've done it (and I know the restore isn't pure but I don't really care):

private class WindowStatus
{
    private WindowState state;
    private Rect restoreBounds;

    public WindowStatus(Window window)
    {
        state = window.WindowState;
        restoreBounds = window.RestoreBounds;
    }

    public void Restore(Window window)
    {
        window.WindowState = state;
        window.Height = restoreBounds.Height;
        window.Width = restoreBounds.Width;
        window.Left = restoreBounds.Left;
        window.Top = restoreBounds.Top;                      
    }

}
yhyrcanus
  • 3,743
  • 2
  • 23
  • 28
0

Can't you just add and manage this property yourself?

Add the property to your form.
Override OnClientSizeChanged and check to see if the window state has changed from Minimized.
If so, set the WindowState to the value of your property.
Set a flag so that you only go through the logic once.

Jacob G
  • 3,645
  • 1
  • 20
  • 25