以编程方式最大化窗口并防止用户更改窗口状态

发布于 2024-09-15 09:12:07 字数 265 浏览 1 评论 0原文

如何以编程方式最大化窗口,以便窗口一旦打开就无法调整大小 达到最大化状态(例如,最大化 Internet Explorer 并查看它)?

我将 FormWindowState 属性设置为

this.WindowState = FormWindowState.Maximized;
this.MaximizedBounds = (x,y);

但它不起作用。我该怎么做?

我想要最大化的窗口是我的应用程序中的一个窗口。

How do I maximize a window programmatically so that it cannot be resized once it
reaches the maximized state (for example, maximize Internet Explorer and see it)?

I set FormWindowState property as

this.WindowState = FormWindowState.Maximized;
this.MaximizedBounds = (x,y);

but it doesn't work. How do I do this?

The window I want to maximize is a window in my application.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

虫児飞 2024-09-22 09:12:07

当表单最大化时,设置其最小尺寸 = 最大尺寸,这样用户就无法调整其大小。

    this.WindowState = FormWindowState.Maximized;
    this.MinimumSize = this.Size;
    this.MaximumSize = this.Size;

When your form is maximized, set its minimum size = max size, so user cannot resize it.

    this.WindowState = FormWindowState.Maximized;
    this.MinimumSize = this.Size;
    this.MaximumSize = this.Size;
等数载,海棠开 2024-09-22 09:12:07

您很接近...在您的 THEN 代码之后

WindowState = FormWindowState.Maximized;

,将表单的最小/最大尺寸容量设置为尺寸确定后的值。

MinimumSize = this.Size;
MaximumSize = this.Size;

You were close... after your code of

WindowState = FormWindowState.Maximized;

THEN, set the form's min/max size capacity to the value once its sized out.

MinimumSize = this.Size;
MaximumSize = this.Size;
晒暮凉 2024-09-22 09:12:07

要在最大化窗口后停止调整窗口大小,您需要将 FormBorderStyleSsized 更改为固定常量之一:

FixedSingle
Fixed3D
FixedDialog

MSDN 页面 备注部分:

表单的边框样式决定表单外边缘的显示方式。除了更改表单的边框显示之外,某些边框样式还会阻止调整表单的大小。例如,FormBorderStyle.FixedDialog 边框样式将窗体的边框更改为对话框的边框,并防止调整窗体的大小。边框样式还会影响表单标题栏部分的大小或可用性。

例如,如果您选择Fixed3D,它将改变表单的外观,如果您希望表单恢复为非最大化状态并再次可调整大小,您可能需要做一些工作。

To stop the window being resizeable once you've maximised it you need to change the FormBorderStyle from Sizable to one of the fixed constants:

FixedSingle
Fixed3D
FixedDialog

From the MSDN Page Remarks section:

The border style of the form determines how the outer edge of the form appears. In addition to changing the border display for a form, certain border styles prevent the form from being sized. For example, the FormBorderStyle.FixedDialog border style changes the border of the form to that of a dialog box and prevents the form from being resized. The border style can also affect the size or availability of the caption bar section of a form.

It will change the appearance of the form if you pick Fixed3D for example, and you'll probably have to do some work if you want the form to restore to non-maximised and be resizeable again.

盗梦空间 2024-09-22 09:12:07

在某些情况下,如果旧答案不起作用,请将属性 WindowState 更改为 System.Windows.Forms.FormWindowState.Maximized

所以窗口将最大化,其他部分在其他答案中。

Change the property WindowState to System.Windows.Forms.FormWindowState.Maximized, in some cases if the older answers doesn't works.

So the window will be maximized, and the other parts are in the other answers.

遥远的她 2024-09-22 09:12:07

要以编程方式最大化窗口状态,您可以使用:

 this.WindowState = FormWindowState.Maximized;
 this.MaximizeBox = false;

To programmatically maximize the windowstate you can use:

 this.WindowState = FormWindowState.Maximized;
 this.MaximizeBox = false;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文