views:

17

answers:

1

I'm trying to save my the state of a System::Windows::Forms::Form when my application shuts down. I can record the window's size, position and window state without any issues but if the window was maximised when it was closed the ::Size member records the maximised size of the window.

Is there any way to record the non-maximised size or do I need to intercept the on-maximise event and record it manually?

+2  A: 

This is not readily available, you'd have to P/Invoke GetWindowPlacement. The best approach is to only record the window size if the form is in the proper state. For example:

    protected override void OnResize(EventArgs e) {
        if (this.WindowState == FormWindowState.Normal)
            Properties.Settings.Default.WindowSize = this.Size;
        base.OnResize(e);
    }
Hans Passant