i have 3 forms.
- main_frm is MDI
- app_frm is child MDI
- progress_frm just a form that shows progress of app_frm
in the progress_frm form i have a button named "cancel" that closes the progress_frm form. Then have the following event on closing the progress_frm.
private void frm_progress_Closing(object sender, FormClosingEventHandler e)
{
Form currentForm = Form.ActiveForm;
Form app_frm_temp = currentForm.ActiveMdiChild;
app_frm_temp.Dispose();
}
I am expecting that the form app_frm will close and terminate anything it was doing. but that does not happen.. only the progress_frm form closes, and i still see app_frm running with the hour glass and still running it's process/thread.
My goal is that if a user wants to abort and close the process that app_frm started, they would be able to terminate and close app_frm from progress_frm?
after the feedback below i tried the following, my form was not hitting the closing event because i copied and pasted it from another form , i then went on the design portion of progress_frm and made an event sorry for confusiong on that :( :
private void progress_frm_FormClosing(object sender, FormClosingEventArgs e)
{
Form currentForm = Form.ActiveForm;
foreach (Form frm in currentForm.MdiParent.MdiChildren)
{
if (frm.GetType() == currentForm.GetType())
{
frm.Focus();
return;
}
}
}
i get a null exception "object reference not set to an instance of an object" when the loop accesses currentForm.. remember my i am the progress_frm which is not part of the MDI config... i am trying to reference and close/terminate the child form app_frm whose parent is main_frm... i know that currentForm is main_frm, but not sure why it will not find the child form so i can reference it?? i tried changing loop to "currentForm.MdiChildren" and still got same null reference exception...
i thought i understood MDI concept, but now am getting confused on how to be able to reference them properly