[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

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...
0
xrok
Asked:
xrok
  • 2
  • 2
1 Solution
 
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
 
gopinathdeepakCommented:
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
 
Eduard GherguCommented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now