By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,183 Members | 1,190 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,183 IT Pros & Developers. It's quick & easy.

MDIForm Parent/Child forms BEST Practice

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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" <ed*****@customercare.com.au> wrote in message
news:d7*************************@posting.google.co m...
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
Nov 20 '05 #2

P: n/a
"Edwinah63" <ed*****@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

Nov 20 '05 #3

P: n/a
yust a side note
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.

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
"Armin Zingler" <az*******@freenet.de> wrote in message
news:40***********************@news.freenet.de... "Edwinah63" <ed*****@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

Nov 20 '05 #4

P: n/a
"EricJ" <er********@ThiSbitconsult.be.RE> schrieb
yust a side note
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.


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.
End Sub

--
Armin

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

Nov 20 '05 #5

P: n/a

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


noted and changed in 2 apps ;) tnx

eric
Nov 20 '05 #6

P: n/a
thanks guys for your thoughts.

Edwina
Nov 20 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.