Disabling Minimize & Maximize On WinForm?

C#WinformsMinimizeMaximize

C# Problem Overview


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?

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

Set MaximizeBox and MinimizeBox form properties to False

Solution 3 - C#

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.

Solution 4 - C#

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.

Solution 5 - C#

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

Solution 6 - C#

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

Solution 7 - C#

public Form1()
{
InitializeComponent();
//this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsoopriseView Question on Stackoverflow
Solution 1 - C#Hans OlssonView Answer on Stackoverflow
Solution 2 - C#volodyView Answer on Stackoverflow
Solution 3 - C#dlras2View Answer on Stackoverflow
Solution 4 - C#Arunkumar PushparajView Answer on Stackoverflow
Solution 5 - C#BracketsView Answer on Stackoverflow
Solution 6 - C#Sameera R.View Answer on Stackoverflow
Solution 7 - C#Mauricio KennyView Answer on Stackoverflow