禁用最小化和最小化在 WinForm 上最大化?
WinForms 在右上角有三个框,分别用于最小化、最大化和关闭窗体。我想要做的是删除最小化和最大化,同时保持关闭。
我还想使关闭最小化表单而不是关闭它。
这怎么能做到呢?
WinForms have those three boxes in the upper right hand corner that minimize, maximize, and close the form. What I want to be able to do is to remove the minimize and maximize, while keeping the close.
I also what to make the close minimize the form instead of closing it.
How can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
Form
有两个属性,分别为MinimizeBox
和MaximizeBox
,将它们都设置为false
。要停止表单关闭,请处理
FormClosing
事件,并在其中设置e.Cancel = true;
,然后设置WindowState = FormWindowState.Minimized;< /code>,最小化表单。
The
Form
has two properties calledMinimizeBox
andMaximizeBox
, set both of them tofalse
.To stop the form closing, handle the
FormClosing
event, and sete.Cancel = true;
in there and after that, setWindowState = FormWindowState.Minimized;
, to minimize the form.将
MaximizeBox
和MinimizeBox
表单属性设置为False
Set
MaximizeBox
andMinimizeBox
form properties toFalse
将处理程序绑定到
FormClosing
事件,然后设置e.Cancel = true
,并设置表单this.WindowState = FormWindowState.Minimized
。如果您想真正关闭表单,请创建一个类范围的布尔值
_close
,并在处理程序中将e.Cancel
设置为!_close
>,这样每当用户单击窗口上的X
时,它都不会关闭,但您仍然可以使用close = true; 关闭它(而不仅仅是杀死它); this.Close();
(只是为了让我的答案完整)将
MaximizeBox
和MinimizeBox
表单属性设置为False
。Bind a handler to the
FormClosing
event, then sete.Cancel = true
, and set the formthis.WindowState = FormWindowState.Minimized
.If you want to ever actually close the form, make a class-wide boolean
_close
and, in your handler, sete.Cancel
to!_close
, so that whenever the user clicks theX
on the window, it doesn't close, but you can still close it (without just killing it) withclose = true; this.Close();
(And just to make my answer complete) set
MaximizeBox
andMinimizeBox
form properties toFalse
.右键单击要隐藏它们的窗体,选择“控件”->“控件”特性。
在属性中,设置
您将在设计器中执行此操作。
Right Click the form you want to hide them on, choose Controls -> Properties.
In Properties, set
You'll do this in the designer.
如何在关闭时使表单最小化已经得到解答,但如何删除最小化和最大化按钮还没有。
FormBorderStyle
:FixedDialog
MinimizeBox
:假
MaximizeBox
:假
How to make form minimize when closing was already answered, but how to remove the minimize and maximize buttons wasn't.
FormBorderStyle
:FixedDialog
MinimizeBox
:false
MaximizeBox
:false
您可以简单地禁用表单构造函数内的最大化。
关闭时最小化。
you can simply disable maximize inside form constructor.
to minimize when closing.
在表单编辑器中选择主表单右键->一直
向下滚动,找到将
MinimiseBox
转为False
,如果你不想的话,与MaximiseBox
相同。就我而言,我刚刚将
MaximiseBox
禁用为False
In the form editor select the main form right-click -> properties
Scroll all the way down, find the
MinimiseBox
turn toFalse
than same withMaximiseBox
if you dont want.In my case i have just disabled the
MaximiseBox
toFalse
如果您想要没有边框和最大化(包括禁用在表单上双击最大化)或最小化,这对我有用:
This works for me if you want no border and no maximize (including disable double click maximize over the form) nor minimize: