如何防止c#

时间:2017-12-27 12:39:12

标签: c# winforms maximize maximize-window formborderstyle

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

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

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

2 个答案:

答案 0 :(得分: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;
    }
}

答案 1 :(得分: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?

相关问题