Jon Cage
Jon Cage

Reputation: 37458

How do I get the non-maximised window size of a form?

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?

Upvotes: 3

Views: 173

Answers (1)

Hans Passant
Hans Passant

Reputation: 941357

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);
    }

Upvotes: 2

Related Questions