3

How do you close a MDI Child form within that child MDI form using a RETURN button which will bring me back to the Parent Form? So far i have used the code:

if (ActiveMdiChild != null)                 
            ActiveMdiChild.Close(); 

But this doesn't work. I have tried numerous methods but nothing has worked so far Any help is much appreciated!!

Eric S
  • 1,336
  • 15
  • 20
jboy
  • 33
  • 1
  • 4
  • Did you try just Close() ? – Rob Nov 18 '16 at 20:55
  • but when you code Close() do i use the forms name? (e.g. frmAddCustomer.Close()) – jboy Nov 18 '16 at 20:59
  • If you are in the form, just call `this.Close();` Not sure what `bring me back to the Parent Form` means since in an MDI application, the parent is always active. – LarsTech Nov 18 '16 at 21:00
  • `ParentForm.ActiveMDIChild().Close();` `MDIForm.Close();` – McNets Nov 18 '16 at 21:03
  • That worked thank you so much LarsTech!! As you can prob tell I am still new to C# so things so simple still prove a struggle to me again thanks so much! – jboy Nov 18 '16 at 21:03

1 Answers1

5

why not use:

foreach (Form c in this.MdiChildren)
{
   c.Close();
}
CDspace
  • 2,639
  • 18
  • 30
  • 36
Joseph Wu
  • 4,786
  • 1
  • 21
  • 19