如何防止c#中的无状态形式最大化

问题描述 投票:1回答:2

我创建了一个表单并将其FormBorderStyle属性设置为none。当我按Windows + UP表格将最大化。我怎样才能防止形式最大化?我试过了

private void logIn_Resize(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Normal;
        }

但它不是我想要的。使用上面的代码,当我按Windows + Up形式将最大化,然后它恢复到正常状态。但我想基本上防止它。

c# winforms maximize maximize-window formborderstyle
2个回答
2
投票

将表单的MaximizeBox设置为False应足以停止此Aero Snap功能。但Form.CreateParams出于某种神秘的原因计算错误的样式标志。由于4.7.1更新,我现在无法单步执行,也没有看到源代码中的错误。它可能与在系统菜单中禁用它而不是样式标志有关,只是一个猜测。

Anyhoo,通过武力锤击本土风格的旗帜确实解决了这个问题。将此代码复制粘贴到您的表单类中:

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

0
投票
// Define the border style of the form to a dialog box.
form1.FormBorderStyle = FormBorderStyle.FixedDialog;

// Set the MaximizeBox to false to remove the maximize box.
form1.MaximizeBox = false;

// Set the MinimizeBox to false to remove the minimize box.
form1.MinimizeBox = false;

感谢How do I disable form resizing for users?

© www.soinside.com 2019 - 2024. All rights reserved.