禁用最小化和最小化在 WinForm 上最大化?

发布于 2024-09-04 22:55:34 字数 109 浏览 11 评论 0原文

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 技术交流群。

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

发布评论

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

评论(9

陌上芳菲 2024-09-11 22:55:35

Form 有两个属性,分别为 MinimizeBoxMaximizeBox,将它们都设置为 false

要停止表单关闭,请处理 FormClosing 事件,并在其中设置 e.Cancel = true;,然后设置 WindowState = FormWindowState.Minimized;< /code>,最小化表单。

The Form has two properties called MinimizeBox and MaximizeBox, set both of them to false.

To stop the form closing, handle the FormClosing event, and set e.Cancel = true; in there and after that, set WindowState = FormWindowState.Minimized;, to minimize the form.

我不会写诗 2024-09-11 22:55:35

MaximizeBoxMinimizeBox 表单属性设置为 False

Set MaximizeBox and MinimizeBox form properties to False

心意如水 2024-09-11 22:55:35

将处理程序绑定到 FormClosing 事件,然后设置 e.Cancel = true,并设置表单 this.WindowState = FormWindowState.Minimized

如果您想真正关闭表单,请创建一个类范围的布尔值 _close ,并在处理程序中将 e.Cancel 设置为 !_close >,这样每当用户单击窗口上的 X 时,它都不会关闭,但您仍然可以使用 close = true; 关闭它(而不仅仅是杀死它); this.Close();

(只是为了让我的答案完整)将 MaximizeBoxMinimizeBox 表单属性设置为 False

Bind a handler to the FormClosing event, then set e.Cancel = true, and set the form this.WindowState = FormWindowState.Minimized.

If you want to ever actually close the form, make a class-wide boolean _close and, in your handler, set e.Cancel to !_close, so that whenever the user clicks the X on the window, it doesn't close, but you can still close it (without just killing it) with close = true; this.Close();

(And just to make my answer complete) set MaximizeBox and MinimizeBox form properties to False.

命硬 2024-09-11 22:55:35

右键单击要隐藏它们的窗体,选择“控件”->“控件”特性。

在属性中,设置

  • 控制框->错误
  • 最小化框 ->错误
  • 最大化框 -> False

您将在设计器中执行此操作。

Right Click the form you want to hide them on, choose Controls -> Properties.

In Properties, set

  • Control Box -> False
  • Minimize Box -> False
  • Maximize Box -> False

You'll do this in the designer.

无名指的心愿 2024-09-11 22:55:35

如何在关闭时使表单最小化已经得到解答,但如何删除最小化和最大化按钮还没有。
FormBorderStyleFixedDialog
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

只为一人 2024-09-11 22:55:35

您可以简单地禁用表单构造函数内的最大化。

 public Form1(){
     InitializeComponent();
     MaximizeBox = false;
 }

关闭时最小化。

private void Form1_FormClosing(Object sender, FormClosingEventArgs e) {
    e.Cancel = true;
    WindowState = FormWindowState.Minimized;
}

you can simply disable maximize inside form constructor.

 public Form1(){
     InitializeComponent();
     MaximizeBox = false;
 }

to minimize when closing.

private void Form1_FormClosing(Object sender, FormClosingEventArgs e) {
    e.Cancel = true;
    WindowState = FormWindowState.Minimized;
}
羁拥 2024-09-11 22:55:35

在表单编辑器中选择主表单右键->一直

向下滚动,找到将 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 to False than same with MaximiseBox if you dont want.

Image

In my case i have just disabled the MaximiseBox to False

冰雪梦之恋 2024-09-11 22:55:35

如果您想要没有边框和最大化(包括禁用在表单上双击最大化)或最小化,这对我有用:

public Form1()
{
    InitializeComponent();
    this.MaximizeBox = false;
    this.ControlBox = false;
    this.FormBorderStyle = FormBorderStyle.FixedSingle;
    this.Text = string.Empty;
}

This works for me if you want no border and no maximize (including disable double click maximize over the form) nor minimize:

public Form1()
{
    InitializeComponent();
    this.MaximizeBox = false;
    this.ControlBox = false;
    this.FormBorderStyle = FormBorderStyle.FixedSingle;
    this.Text = string.Empty;
}
偏爱自由 2024-09-11 22:55:35
public Form1()
{
InitializeComponent();
//this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
}
public Form1()
{
InitializeComponent();
//this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文