开发者

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

开发者 https://www.devze.com 2023-01-04 06:50 出处:网络
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 stat开发者_开发问答e without any issues but if t

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 stat开发者_开发问答e 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?


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

精彩评论

暂无评论...
验证码 换一张
取 消