中最大化无状态形式

中最大化无状态形式

本文介绍了如何防止在c#中最大化无状态形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i have created a form and set its FormBorderStyle property to none.when i press Windows + UP form will be Maximized. how can i prevent form from maximize?i tried

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

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

but its not that i want. with above code when i press Windows + Up form will maximize and then it restores to normal state. but i want to prevent it basically.

推荐答案

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

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,用武力敲掉原生样式的标志确实可以解决问题.将此代码复制粘贴到您的表单类中:

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

这篇关于如何防止在c#中最大化无状态形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:22