Prevent use of the X to close a window

One option is to complete remove the control box (minimize, Maximize and close)

in the InitializeCustomCode() method add this.PartForm.ControlBox = false;

replace PartForm with the form you are using