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

WinForms 在右上角有三个框,可以最小化、最大化和关闭表单。我希望能够做的是去除最小化和最大化,同时保持关闭。

我还要使关闭的形式最小化而不是关闭它。

这怎么可能呢?

173734 次浏览

Set MaximizeBox and MinimizeBox form properties to False

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.

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.

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;
}

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.

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

public Form1()
{
InitializeComponent();
//this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = 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