[英]how to prevent none state form from being maximized in c#
我创建了一个表单并将其FormBorderStyle
属性设置为none
。 当我按Windows + UP
表格将最大化 。 我怎样才能防止形式最大化? 我试过了
private void logIn_Resize(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
}
但它不是我想要的。 使用上面的代码当我按下Windows + Up
表单将最大化然后它恢复到正常状态。 但我想基本上防止它。
将表单的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;
}
}
// 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.