Hello, I have a simple question. How do I make it so that the application I'm making doesn't close when the startup form closes and make it close when the last form closes?
Thanks for the help
Printable View
Hello, I have a simple question. How do I make it so that the application I'm making doesn't close when the startup form closes and make it close when the last form closes?
Thanks for the help
One way to do this would be:
Have a boolean value that keeps track wether the parent form is "closed" or not. Then have booleans to determine wether any child forms are open or not.
Whenever a user decides to close the main window, instead of closing it, just hide the window, adjust the boolean value and cancel the closing action.
something like:
Every other window also has this windowOpen boolean. If it is false its closed , else its up and running.Code:private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
this.mainWindowOpen = false;
this.Hide();
e.Cancel = true;
}
One minor catch, if you launch a second window, close the main window, close the second window... the main window will still be running but it is hidden.
To overcome this: on each closing of a child window, go over all the booleans, if all booleans are set to false then this means you should really close the application ( killing the main window ).