I have total 4 forms .. when a button on form2 is clicked it loads form3 and minimize form2 and on close of form3 it refocus form2 and same with form4 it loads from a button on form3 and form3 is minimized
so if I returned to form2 and clicked the x button it gives an error because form3 wants to refocus form2 that is already closing
please help

VulpesRank #55 · 29.2K reputationPosted Jan 24, 2014, 10:01 AM EST
You can kill the process by calling Environment.Exit(1) rather than Application.Exit().
However, this kills it stone dead and so if you're relying on FormClosing or FormClosed eventhandlers running, then I'd place it just after Application.Run in the Main() method and call Application.Exit where you're calling it now.
VulpesRank #55 · 29.2K reputationPosted Jan 24, 2014, 9:29 AM EST
If you want to close all open forms, then your best option is to close the start-up form, Form1, as this will automatically close the others:
Form1 f1 = Application.OpenForms["Form1"] as Form1;
f1.Close();
You could also call Application.Exit() which (more or less) does the same thing.
mind controll144 reputationPosted Jan 24, 2014, 9:39 AM EST
closing form1 method worked for me but the application process is still running that's why I was using this ..
Application.Exit();
Process[] localByName = Process.GetProcessesByName("myapp");
foreach (Process p in localByName)
{
p.Kill();
}
how can I do both .. closing main form and also kill the app process ?
mind controll144 reputationPosted Jan 24, 2014, 10:03 AM EST