That is a bad idea. There's generally no reason that you should not let the user close the form from the Close button on the title bar. If you want to make sure that the user saves their work then you should check for pending changes in the FormClosing event and then prompt the user if there are pending changes. You can then let the user choose to cancel the close then if they want. If there really is a legitimate reason that you don't want the user to use the Close button on the title bar then don't let them press it at all. Generally the only reason to disallow its use is in a dialogue box, in which case you shouldn't need the Maximize or Minimize buttons either, so you can set the form's ControlBox property to False to remove them all. If you do need the Maximize and Minimize buttons then you should use the Windows API to disable the Close button. See the link below for how to do that.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.