Closing multiple Forms within application
Posted: Thu Aug 09, 2012 5:57 am
Hi,
Just wondering ... is there some generic code i can use to close all forms within an application that have dependency forms popup when you havn't saved the changes on these forms?
e.g the application I have, has the ability to create objects using a Property Page Form. If this forms is left open ... can you close/dispose of it dynamically (using a code module) even when a modal form pops up saying "Do you want to save changes" Yes, No, Cancel?
I have found the following code works well, when the forms have no changes on them. (As the dependency form is not shown)
IList<Form> allForms = Host.Local.FindChildren<Form>();
foreach (Form frm in allForms)
{
if (frm.State == WinForms.FormWindowState.Normal)
{
frm.Close();
}
}
Is there a better way of doing this ... regardless of whether a dependency form pops up?
Brad.
Just wondering ... is there some generic code i can use to close all forms within an application that have dependency forms popup when you havn't saved the changes on these forms?
e.g the application I have, has the ability to create objects using a Property Page Form. If this forms is left open ... can you close/dispose of it dynamically (using a code module) even when a modal form pops up saying "Do you want to save changes" Yes, No, Cancel?
I have found the following code works well, when the forms have no changes on them. (As the dependency form is not shown)
IList<Form> allForms = Host.Local.FindChildren<Form>();
foreach (Form frm in allForms)
{
if (frm.State == WinForms.FormWindowState.Normal)
{
frm.Close();
}
}
Is there a better way of doing this ... regardless of whether a dependency form pops up?
Brad.