【问题标题】:how to prevent none state form from being maximized in c#如何防止无状态形式在c#中最大化
【发布时间】:2018-06-08 02:36:58
【问题描述】:

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

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

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

【问题讨论】:

  • @Hans 您可能会考虑仔细查看它(对于错误或其他东西),因为当FormBorderStyle.None 时似乎没有什么可以阻止这种行为

标签: c# winforms maximize maximize-window formborderstyle


【解决方案1】:
// 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?

【讨论】:

  • 我想要一个带有 formBorderStyle.none 的表单
  • 我确信有多种方法可以做到这一点,但这就是我所展示的。 FixedDialog 将停止手动调整大小。 MaximiseBox = False 阻止您最大化窗口,MinimiseBox = False 应该为最小化做同样的事情。
【解决方案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;
    }
}

【讨论】:

    猜你喜欢
    • 2015-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 2014-10-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多