Re: MDIForm Parent/Child forms BEST Practice

From: Armin Zingler (az.nospam_at_freenet.de)
Date: 04/22/04


Date: Thu, 22 Apr 2004 10:30:51 +0200


"Edwinah63" <edwinah@customercare.com.au> schrieb
> Hi everyone,
>
> could someone give me some thoughts on the best way to manage mdi
> parent and child forms?
>
> in vb6 i could scroll through the forms collection and determine
> which forms were open/closed and their current state. now i
> can't.

You have the MdiChildren property in the MDI form.

> before i didn't have to declare numerous named instances each time
> i loaded or unloaded a form.

If you don't need to handle them specifically, an array, or Arraylist or
whatever would be sufficient. Or the mentioned Mdichildren property.

> if i open a child form from another child form and try to assign
> mdimain as the mdiparent it doesn't permit it, if i say f1.mdiparent
> = me.mdiparent i get memory problems (as have others judging from
> the groups).
>
> all my current forms are declared public shared in mdiMain, but
> should these be in a user made forms collection owned by a global
> module (cMain)?

I'd keep them in the MDI parent. I'd not even declare them public, but
instead pass references if needed.

> if i am finished with a child form, i want to unload it, not hide
> it, but if i close a form in vb.net it extinguishes the instance.
>
> when the mdi parent closes, i would like the app to terminate.
>
> should i be setting mdi children to nothing or disposing them?

No, not necessary. The children are closed before the parent is closed, and
closed forms are also disposed automatically.

> basically, what can/should i do to get the same mdi parent/child
> management present in vb6 while still preserving the smallest
> footprint possible in memory?
>
> all comments/code greatly appreciated. i am probably not the only
> programmer to ponder this question.

I'm not sure what's exactly your problem. I don't have memory problems. If I
wanted to create and later access an object (like a Form), I'd declare a
variable to store the reference. You can create one variable per Form
(advantage: don't have to search for it in a collection) or store them all
in a collection (advantage: no single variables needed), or both. Or use a
Hashtable to store them. If there can be only one instance of each Form
class, you could use the class name as the key (form.gettype.fullname).

-- 
Armin
How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html


Relevant Pages

  • Re: My.Application.OpenForms
    ... ' parent the form the the MDI Container ... ' make the form fill the client area of the MDI Container ... Have you solved the problem of sizing a child form to fit the MDI client ... 'enable application framework' checkbox is unchecked. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: ShowDialog()
    ... Basically You need a parent form, which has the IsMdiContainer property set to true. ... This will be the main window, the MDI parent. ... Then You can add child forms, by setting the child forms MdiParent property to the parent form, and then calling Show on it. ... How can I show 'classic mdi form' within the mdi control (microsoft or any ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Multi-window application example
    ... How do you resize a MDI child form to fit the Client Rectangle in the parent ... MDI in vb.net without the scroll bars appearing???? ... dynamiccally built forms and opens and closes forms as necessary and can ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: MDIForm Parent/Child forms BEST Practice
    ... >> should i be setting mdi children to nothing or disposing them? ... This has coused problems for me in the past (on a standard create parent ... >> could someone give me some thoughts on the best way to manage mdi ... >> if i open a child form from another child form and try to assign ...
    (microsoft.public.dotnet.languages.vb)
  • Re: mdi child forms not closing in the right order
    ... you use the closing event to trigger some subs. ... > You would go though the parents mdichildren property and the children forms are in order as they were added as mdi children to the parent. ... > You would create a standard interface and all child forms would implement this interface. ...
    (microsoft.public.dotnet.framework.windowsforms)

Loading