Results 1 to 3 of 3

Thread: Closing MDI Parent form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    91

    Closing MDI Parent form

    Hai

    i am working with MDI forms. i am having parent form (mainfrm). and child forms(chld1,chl2)


    from mainfrm i opened chld1 using

    chld1.show();


    now if i close parent form (mainfrm) the child windows r getting closed. i should restrict user to close parent form when child form is opened.

    for that i am trying to use

    chld.ShowDialog();

    But unable to do that


    Please help me in this regard


    Thanks and Regards
    VInay Kumar

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Closing MDI Parent form

    An MDI child form cannot be a modal dialogue. To prevent the parent form closing you can handle the FormClosing event:
    Code:
    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        // Cancel the closing action if and only if there are child forms.
        e.Cancel = (this.MdiChildren > 0);
    }
    Note that this assumes that you're using VB2005. In previous versions you'd handle the Closing event instead. Please make sure you specify your version in future.

    Also, this will prevent Windows shutting down if your app has child forms open. You'd have to make a special case for if the system was shutting down. I don't know exactly how to do that because I've never had to myself but I know that the appropriate code has been posted before.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    91

    Re: Closing MDI Parent form

    Thats a great reply. Thank u so much


    Just one more doubt added to it.


    i am having parent form(mainfrm)

    i am having 2 child forms(frm1,frm2)

    i will go to frm1 and frm2 through mainfrm

    if frm1 or frm2 is open, i should not able to select mainfrm


    like frm1.ShowDialog();
    but if i am using this in MDI i am getting error

    Can i get answer for this one too.


    Thank u so much in Advance

    Regards
    Vinay Kumar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width