Page 1 of 1

Closing multiple Forms within application

Posted: Thu Aug 09, 2012 5:57 am
by bsing
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.

Re: Closing multiple Forms within application

Posted: Thu Aug 09, 2012 1:50 pm
by Support Team
Hi,

You can check if an attribute changes the state if the popup is open, e.g. the 'Active' attribute or the 'Enabled' attribute. If this is the case you can close the form as you described depending on the property.
The popup and the form will be closed then.

Regards
Bernhard
Ranorex Support Team

Re: Closing multiple Forms within application

Posted: Tue Aug 14, 2012 1:06 am
by bsing
I can't check these attributes (Enabled, Active) as you mentioned, as the code will not execute until the modal dialog is closed. I have tried multi-threading to get around this and it works fine. However I could only identify the button to close both modal dialog and form using repo.form.button.etc etc.

How can I identify the button without using this syntax and then click it?

Re: Closing multiple Forms within application

Posted: Tue Aug 14, 2012 1:50 pm
by Support Team
Hello Brad,

You can directly acces the button via the RxPath.
Button btn = "/form[@controlname='Form1']/button[@controlname='button1']";
btn.Click();
If I misunderstood your question please explain it again.

Regards,
Bernhard
Ranorex Support Team

Re: Closing multiple Forms within application

Posted: Mon Aug 20, 2012 10:09 am
by artur_gadomski
If you don't mind loosing unsaved changes you might want to press Esc key that sometimes disposes of popups.