Link to home
Start Free TrialLog in
Avatar of csharp_learner
csharp_learnerFlag for Singapore

asked on

Close parent and child Form C#

Hi, I'm currently handling with 3 Forms.
A Main Form,Parent Form and a child Form.
The relation is the Main form has a link to the parent form.
The Parent Form links to a Child Form after a button event.

My question is How can Close the ChildForm and ParentForm at the same time when I close the ChildForm?
//Main Form link
            parentForm Pdetails = new  parentForm();
            Pdetails.ShowDialog();
            Pdetails.Dispose();
 
//Parent Form
                childForm Cconfirm = new childForm(confirmlist);
                Cconfirm.Show();
 
//Child Form (How to close ParentForm also???)
            this.DialogResult = DialogResult.Cancel;
            this.Close();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of csharp_learner

ASKER

Thanks for the reply,I followed your step but my parent Form
        private void newDataPoint_Click(object sender, EventArgs e)
        {
            MyChildForm child = new MyChildForm();
            child.ShowDialog();
            child.Dispose();
        }
"MyChildForm child = new MyChildForm();"does not take '0' arguments.What should I include inside?
I tried MyChildForm child = new MyChildForm(this); but doesn't work
my bad MyChildForm child = new MyChildForm(this); worked.