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

Posted on 2005-05-10
Last Modified: 2010-04-17
i have an MDI application with multiple child do i close any open child forms so that only one child form is open at a time...
Question by:xrok
    LVL 4

    Expert Comment

    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)

    dim child1 as new childform1()
    child1.MDIParent = MDIParentForm1
    LVL 3

    Author Comment

    how well does the Close function release the form object? i have critical memory management issues in my application..
    LVL 4

    Accepted Solution

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

    LVL 10

    Expert Comment

    by:Eduard Ghergu
    Unfortunatelly, there is no Forms collection in VB.NET... So, you have to create your own collection. You'll find an example at:
    LVL 3

    Author Comment

    i was afraid of that.  I will use hide instead.  ty

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    Title # Comments Views Activity
    Safe way to use a password in a bat or cmd file? 8 46
    centeredAverage challenge 8 89
    thread-safe code in c++ 2 58
    Specific format 21 105
    Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
    RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now