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
.