I'm writing a multi form application, and I'd like to be able to close Form1 with out the application closing.
Right now i'm using this.Hide
to hide the form. Is there a way to set it so i can close any form, or the application should only exist when all the forms are closed?
I think i remember seeing something like that at one point, but that might not have been visual studio and c#.
In your Program.cs
file you have a line like Application.Run(new Form1())
. Replace it with
var main_form = new Form1();
main_form.Show();
Application.Run();
Also you need to close application explicitly by call Application.Exit()
where you want.
One strategy is to do something like the following:
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
if (Application.OpenForms.Count == 0)
Application.Exit();
}
}
If you place this on all of your forms, when the last one closes, the application will exit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With