I have an application that has a main form and a user can create a number of
other forms at run time. Most of those forms are created through reflection
by first using Assembly.CreateInstance to create the object then get the
methodInfo of a certain method, and finally calls MethodInfo.Invoke.

At certain point of the execution I need to close all those forms except my
main form.
Anybody knows if there is a way of finding all those forms from my main
form?
Thanks.

Re: finding all the opened forms by Sijin

Sijin
Tue Nov 09 03:23:03 CST 2004

There is no built-in mechanism, what you will have to do is have a
global static collection of all dynamically opened forms. Whenever you
open a new form, you need to add that form reference to the list and
whenever you close a form you need to delete the reference from this list.


Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

Jia wrote:
> I have an application that has a main form and a user can create a number of
> other forms at run time. Most of those forms are created through reflection
> by first using Assembly.CreateInstance to create the object then get the
> methodInfo of a certain method, and finally calls MethodInfo.Invoke.
>
> At certain point of the execution I need to close all those forms except my
> main form.
> Anybody knows if there is a way of finding all those forms from my main
> form?
> Thanks.
>
>
>
>

Re: finding all the opened forms by Mark

Mark
Tue Nov 09 11:04:41 CST 2004

Hi Jia, Joseph's suggestion would work fine.
Additionally I have another method which I prefer and that is to subscribe
each form's close method to a
particular delegate.
Additionally within each forms closed event handler remove them from this
delegate (so they won't be fired again).
Therefore the delegate list will only fire any forms close methods if they
are open.
It is simple, and works a treat.

Br,

Mark.

"Jia" <jlizhi@epicor.com> wrote in message
news:eNvBN4axEHA.1400@TK2MSFTNGP11.phx.gbl...
>I have an application that has a main form and a user can create a number
>of
> other forms at run time. Most of those forms are created through
> reflection
> by first using Assembly.CreateInstance to create the object then get the
> methodInfo of a certain method, and finally calls MethodInfo.Invoke.
>
> At certain point of the execution I need to close all those forms except
> my
> main form.
> Anybody knows if there is a way of finding all those forms from my main
> form?
> Thanks.
>
>
>
>



RE: finding all the opened forms by NigelArmstrong

NigelArmstrong
Fri Nov 12 07:46:03 CST 2004

Hi Jia

One more idea for you - you can set the Owner property of the new forms to
the main form in the application. Then the main form can use its OwnedForms
property to iterate through all these forms.

The downside of this is that the OwnedForms always float on top of the Owner
(it may not be a downisde for you of course) - if you don't want this, then
you will need a mechanism like the one the other posters have outlined.

HTH

Nigel

"Jia" wrote:

> I have an application that has a main form and a user can create a number of
> other forms at run time. Most of those forms are created through reflection
> by first using Assembly.CreateInstance to create the object then get the
> methodInfo of a certain method, and finally calls MethodInfo.Invoke.
>
> At certain point of the execution I need to close all those forms except my
> main form.
> Anybody knows if there is a way of finding all those forms from my main
> form?
> Thanks.
>
>
>
>
>