MDIForm Parent/Child forms BEST Practice

E

Edwinah63

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.

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

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)?

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?

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.

regards

Edwinah63
 
E

EricJ

I don't know if w i do is the best way of doing things but it works. i'll
try to put it under your questions.

Edwinah63 said:
Hi everyone,

could someone give me some thoughts on the best way to manage mdi
parent and child forms?

First i always create a public var of my main form (mdi parent) for easy
access (yust declare it in a module and i the parent.load set the var to me)
in vb6 i could scroll through the forms collection and determine which
forms were open/closed and their current state. now i can't.

something like this?
For Each f As Form In fmMain.MdiChildren
If f.Visible Then

End If
Next

before i didn't have to declare numerous named instances each time i
loaded or unloaded a form.
the named instance is declared locally so once you are out of this sub it is
gone
Dim manPSNT As New frmManPSNType
manPSNT.MdiParent = Me
manPSNT.Show()
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).

I use the public instance of my main form to do this. But i have don it w
the me.MdiParent should work. (unless you are doing strange things in the
client forms, try loading them non mdi first)
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)?

you that would be more organized but generally you don't need them all
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.
sounds right you will have to assign a new instance of the form to the var,
it all depends on w you want to do at that givven time.
when the mdi parent closes, i would like the app to terminate.
try this

Private Sub frmMain_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
Application.Exit()
End Sub
should i be setting mdi children to nothing or disposing them?
..NET will do that for you

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?

if you want less mem don't declare all your forms as globals, .NET handles
it rather good the standard way.
all comments/code greatly appreciated. i am probably not the only
programmer to ponder this question.

regards

Edwinah63


There are probably bether ways to do some things, comments are welcome.
Hope it helps a bit

Eric
 
A

Armin Zingler

Edwinah63 said:
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
 
E

EricJ

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

This has coused problems for me in the past (on a standard create parent
first and do everithing in childs it should work) but it dousn't hurt to use
this
Private Sub frmMain_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
Application.Exit()
End Sub


eric
 
A

Armin Zingler

EricJ said:
yust a side note


This has coused problems for me in the past (on a standard create
parent first and do everithing in childs it should work) but it
dousn't hurt to use this
Private Sub frmMain_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
Application.Exit()

If it's really necessary as you say, I'd use Application.ExitThread.


--
Armin

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top