473,387 Members | 1,611 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

MDIForm Parent/Child forms BEST Practice

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
6 9402
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
"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
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
"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

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
thanks guys for your thoughts.

Edwina
Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Debi | last post by:
Hi, I added a few buttons to the Mdi form, to call the child forms in the button click event. But when the child window opens, all the buttons are displayed in front of the child window. Any...
0
by: amber | last post by:
Help! In my project, I have a 'navigation' form that opens first, and from there the user chooses from multiple 'modules'. Each module has a 'main' form that contains a menu to open many...
25
by: Steve Jorgensen | last post by:
Yup, Steve's full of tips, but hey, it makes him feel important, right? Ok, here goes. I've been trying to improve encapsulation by putting code in the same object as the stuff it affects, so I...
3
by: Maheshkumar.R | last post by:
Hi groups, How i can command over the MDI CHIlD forms created dynamically at runtime from PARENT. Let say, i have generated 5 mdichild forms, but i want to work with child form1 from MDI...
2
by: Jim Shank | last post by:
I am really trying to find the best OOP way of doing this. I have a parent MDI form with multiple children and I am trying to communicate variables between them. I have been able to successfully...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
2
by: JohnR | last post by:
Let's say I have an MDI parent form with a textbox. If I create an MDI child form and, at runtime, move the MDI child window over the textbox on the MDI parent, the textbox appears in front of the...
2
by: Ben | last post by:
after I migrated to dotNet, code wizard never bothered upgraded my MDIform background embedded pictures b/c MS is no longer providing us with that feature. Is there an alternative solution that...
6
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
What would cause VS2005 Pro to lose all of my MdiForm Design information? I've been working on one of the Child Forms and having problems with the Child Form's threads not completing (locking up...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.