以编程方式最大化窗口并防止用户更改窗口状态
如何以编程方式最大化窗口,以便窗口一旦打开就无法调整大小 达到最大化状态(例如,最大化 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当表单最大化时,设置其最小尺寸 = 最大尺寸,这样用户就无法调整其大小。
When your form is maximized, set its minimum size = max size, so user cannot resize it.
您很接近...在您的 THEN 代码之后
,将表单的最小/最大尺寸容量设置为尺寸确定后的值。
You were close... after your code of
THEN, set the form's min/max size capacity to the value once its sized out.
要在最大化窗口后停止调整窗口大小,您需要将
FormBorderStyle
从Ssized
更改为固定常量之一:从 MSDN 页面 备注部分:
例如,如果您选择
Fixed3D
,它将改变表单的外观,如果您希望表单恢复为非最大化状态并再次可调整大小,您可能需要做一些工作。To stop the window being resizeable once you've maximised it you need to change the
FormBorderStyle
fromSizable
to one of the fixed constants:From the MSDN Page Remarks section:
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.在某些情况下,如果旧答案不起作用,请将属性
WindowState
更改为System.Windows.Forms.FormWindowState.Maximized
。所以窗口将最大化,其他部分在其他答案中。
Change the property
WindowState
toSystem.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.
要以编程方式最大化窗口状态,您可以使用:
To programmatically maximize the windowstate you can use: