Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling Minimize & Maximize On WinForm?

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?

like image 442
sooprise Avatar asked Jun 11 '10 20:06

sooprise


People also ask

How do I stop my screen from minimizing?

Open the Windows Settings. Select the System option. Click on the Display tab. Uncheck the Minimize windows when a monitor is disconnected option.

Why does my screen minimize by itself?

Your monitor flickers because your computer has its refresh rate, the rate at which the images on the monitor refresh themselves, set to be incompatible with your monitor. Windows can minimize for a variety of reasons, including refresh rate problems or software incompatibility.


2 Answers

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.

like image 123
Hans Olsson Avatar answered Oct 01 '22 19:10

Hans Olsson


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.

like image 36
dlras2 Avatar answered Oct 01 '22 18:10

dlras2