Simple Code for .net - Best way to close child form

i have an MDI application with multiple child forms..how do i close any open child forms so that only one child form is open at a time...
LVL 3
xrokAsked:
Who is Participating?
 
gopinathdeepakConnect With a Mentor Commented:
i presume u mean memory leaks....

if u have child forms on and off all the time....meaning u create and destroy them all the time, u might want to use the Form.Hide function istead of Close....because that way the form stays in memory and theres no question of de-allocating and re-allocating memory...it also makes the application faster..

if u go the other way, u may find (as i did in one of my apps) that the memory of the previous object (which u disposed by useing Form.Close) is not released by the app sometimes giving the impression that the application is hogging the memory...

so in MDI apps, in my opinion Form.Hide if judiciously used can perform better....

0
 
gopinathdeepakCommented:
try this code...
assuming MDIParentForm1 to be an instance of the parent form in your mdi application,


dim i as integer = 0

for i=0 to MDIParentForm1.MdiChildren.GetLength(0)
    MDIParentForm1.MdiChildren(i).Close()
next

dim child1 as new childform1()
child1.MDIParent = MDIParentForm1
child1.Show()
0
 
xrokAuthor Commented:
how well does the Close function release the form object? i have critical memory management issues in my application..
0
 
Eduard GherguLeader SibiuCommented:
Hello!
Unfortunatelly, there is no Forms collection in VB.NET... So, you have to create your own collection. You'll find an example at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vaconCreatingYourOwnCollectionClass.asp
0
 
xrokAuthor Commented:
i was afraid of that.  I will use hide instead.  ty
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.