none
Sub/Child Form Closing While Cliking on the Main/Parent Form RRS feed

  • Question

  • Hi,

    i am having some trouble in my Windows form application. i have 2 forms 

    1st Main / Parent Form

    2nd Sub / Child Form (Menu)

    Problem:

    i want to close my 2nd form (which opens on top of 1st form) when i click on 1st form.

    Kindly Replay soon..

    Tuesday, June 5, 2012 12:23 PM

Answers

  • That's the way modal forms work.  If modeless behavior is a requirement, consider changing your design.


    This signature unintentionally left blank.

    Wednesday, June 6, 2012 11:01 AM

All replies

  • Create a variable for your child form as a member of your main form:

        private MyChildForm child = null;

    when you create and display your child form, save the reference:

        child = new MyChildForm();
        child.Show();

    add a mouse click event handler to your main form with code to close the child:

        if (null != chilid)
        {
            child.Close();
            child = null;
        }


    This signature unintentionally left blank.

    • Proposed as answer by Kris444 Tuesday, June 5, 2012 3:54 PM
    Tuesday, June 5, 2012 3:28 PM
  • Hi, 

    On what action you are trying to close form?

    You can also look into form click event..

    void ParentForm_Click(object sender, EventArgs e) { childForm.Close(); }



    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".

    • Proposed as answer by Pantelis44999 Tuesday, June 5, 2012 11:25 PM
    Tuesday, June 5, 2012 3:54 PM
  • My Forms are Modal Forms.

    Parent form is deactivated when child form opens and until user click OK or cancel  button in child form (means we have to close child form to activate Parent form). and mouse click event not worked in that situation.


    Wednesday, June 6, 2012 9:28 AM
  • That's the way modal forms work.  If modeless behavior is a requirement, consider changing your design.


    This signature unintentionally left blank.

    Wednesday, June 6, 2012 11:01 AM