116

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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
sooprise
  • 22,657
  • 67
  • 188
  • 276

9 Answers9

184

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.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
19

Set MaximizeBox and MinimizeBox form properties to False

pb2q
  • 58,613
  • 19
  • 146
  • 147
volody
  • 6,946
  • 3
  • 42
  • 54
17

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.

dlras2
  • 8,416
  • 7
  • 51
  • 90
12

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.

Jeff B
  • 8,572
  • 17
  • 61
  • 140
6

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

Brackets
  • 464
  • 7
  • 12
3

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;
}
Sameera R.
  • 4,384
  • 2
  • 36
  • 53
0
public Form1()
{
InitializeComponent();
//this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
}
0

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

unofficialdxnny
  • 105
  • 1
  • 7
0

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