Basically I have an application that I have written in which I use a number of forms however when I no longer want to view the form I hide it as opposed to closing it. I do this because I need to retain the data that is on the form and so making it invisible is the easyest way of doing it.

If you close a form with the X is the top right the program ends only if there are no other objects active.

This is a problem in when I want to close the main form by clicking on the X in the top right because the other forms are still active the program is still running even though there are not visible forms on the screen.


My question is:

How can I either use the X in the top right to run some code that unloads all the forms that I have open or how can I disable the X in the top right whilst keeping the max and min buttons?

Thanks for your help.

Any further information required please ask