473,699 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9419
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*****@custom ercare.com.au> wrote in message
news:d7******** *************** **@posting.goog le.com...
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.MdiChild ren
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.MdiPare nt = 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.EventArg s) Handles MyBase.Closed
Application.Exi t()
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*****@custom ercare.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.f ullname).
--
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.EventArg s) Handles MyBase.Closed
Application.Exi t()
End Sub
eric
"Armin Zingler" <az*******@free net.de> wrote in message
news:40******** *************** @news.freenet.d e... "Edwinah63" <ed*****@custom ercare.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.f ullname).
--
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********@Thi Sbitconsult.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.EventArg s) Handles MyBase.Closed
Application.Exi t()


If it's really necessary as you say, I'd use Application.Exi tThread.
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.Exi tThread.


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
2027
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 idea on how to fix this. Thanx, Debi
0
975
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 different forms and reports. Now I have the first 'navigation' form set as the parent form, with each module's main form opening as a child. Now my problem is, logically, all my main 'module' forms should be parents
25
6200
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 rarely refer to a subform ir parent form's controls or records from the other form. Instead, I call a procedure in that form that does the job. That's all fine and good, and nothing at all revolutionary, but it leaves one with an annoying...
3
9701
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 parent menu functions. if i select draw line in MDI parent, the line should be drawn in current active child..any URLS for this or guide me to achieve this communication... -- Mähésh Kumär. R
2
3435
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 get the parent form to read the child variable by using a Public Property in one of my child forms like such: Public ReadOnly Property ID() As String Get Return strID End Get
10
4017
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 application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms, remove the controls on each of them, and then close the form, but this code should execute only...
2
14018
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 MDI child window. How can I make the MDI child window appear in front of any controls that may be on the MDI parent? thanks, John
2
2263
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 would let me embed my background bitmap/jpeg picture into my MDI form? And to make it autosketch as well? thanks.
6
2269
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 and not responding anymore). So, I shut down VS, turned off my PC, then turned everything back on. Now, my MdiForm Design looks like a blank form whenever a new form is added to a project. My Tray Icon, Status Bar strip, and Main Menu are all...
0
8706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8630
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8944
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7786
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4638
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.