Thread: Program closes when startup form closes

  1. #1
    Registered User
    Join Date
    Apr 2006

    Program closes when startup form closes

    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

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    between photons and phonons
    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:

    		private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
    			this.mainWindowOpen = false;
    			e.Cancel = true;
    Every other window also has this windowOpen boolean. If it is false its closed , else its up and running.

    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 ).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. make my program start on startup.
    By XunTric in forum Windows Programming
    Replies: 11
    Last Post: 01-12-2006, 07:26 PM
  4. startup program deleting shutdown? Need help
    By Miestese in forum Linux Programming
    Replies: 2
    Last Post: 07-06-2005, 09:05 PM
  5. Computer Startup Log Program
    By Junior89 in forum C++ Programming
    Replies: 8
    Last Post: 01-11-2005, 11:00 PM