Closing multiple Forms within application

Class library usage, coding and language questions.
bsing
Posts: 81
Joined: Tue Feb 07, 2012 5:25 am

Closing multiple Forms within application

Post by bsing » 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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Closing multiple Forms within application

Post by Support Team » Thu Aug 09, 2012 1:50 pm

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

bsing
Posts: 81
Joined: Tue Feb 07, 2012 5:25 am

Re: Closing multiple Forms within application

Post by bsing » Tue Aug 14, 2012 1:06 am

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Closing multiple Forms within application

Post by Support Team » Tue Aug 14, 2012 1:50 pm

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

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Closing multiple Forms within application

Post by artur_gadomski » Mon Aug 20, 2012 10:09 am

If you don't mind loosing unsaved changes you might want to press Esc key that sometimes disposes of popups.