hello :)

i wanted to know, how can i change the shutdown mode of my Windows Form Application, @ MS Visual studio 2010.
i.e, my application should exit only when i close my last form.. & not when the main form is closed..

i remember, in .NET 2003 windows form application, i used to write following lines to move to forms to forms:

private void button1_Click(object sender, EventArgs e)
        {
            All_Deposits ad = new All_Deposits();
            ad.Show();
            this.Close();
        }

this always worked perfectly.. but i'm in visual studio 2010, application exits, soon as this.Close() is called for the main form... so how can i change the app shutdown mode..?

thanks :)

YOu have to be aware of one thing: when you close the form (main form you named it), which has been started from Program class with:

 Application.Run(new Form1());

The application will close.
To avoid this, you have to take care of closing all other form before this one.

thanks for the reply :)

yea, but i want to move to my second form, from first (main) form. and i want my first (main) form to be closed, soon as the new second form appears. as i mentioned in post, in code, i used to do in .NET 2003, & it worked perfect. but in visual studio 2010, it doesn't work, as u mentioned, that application closses, soon as the main form is closed..
so, how can i change this settings?? so that my new form appears, and main is closed.
i tried to call:

this.hide();

but wen i close the application from the last form, where finally i am, the main form still exists running in proccess. (application doesn't close, cz first form is still in processes).

thanks :)

You can use Form_Closing event, and add a Application.Exit(); to the bottom of it, ex:

private void mainForm_FormClosing(object sender, FormClosingEventArgs e)
{
    Application.Exit();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.