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
VulpesPosted Jan 24, 2014, 3:01 PM
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.
mind controllPosted Jan 24, 2014, 3:03 PM
mind controllPosted Jan 24, 2014, 2:39 PM
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 ?
VulpesPosted Jan 24, 2014, 2:29 PM
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.