how to prevent none state form from being maximized in c#

后端 未结 2 563
清酒与你
清酒与你 2021-01-24 15:56

i have created a form and set its FormBorderStyle property to none. when i press Windows + UP form will be Maximized. how

2条回答
  •  孤独总比滥情好
    2021-01-24 16:28

    Setting the form's MaximizeBox to False should be enough to stop this Aero Snap feature. But Form.CreateParams calculates the wrong style flags for some mysterious reason. I can't single-step it right now due to the 4.7.1 update and don't see the mistake in the source code. It might have something to do with disabling it in the system menu but not the style flags, just a guess.

    Anyhoo, hammering the native style flag off by force does solve the problem. Copy-paste this code into your form class:

    protected override CreateParams CreateParams {
        get {
            const int WS_MAXIMIZEBOX = 0x00010000;
            var cp = base.CreateParams;
            cp.Style &= ~WS_MAXIMIZEBOX;
            return cp;
        }
    }
    

提交回复
热议问题