Can an MDI child close and MDI parent?

Can an MDI child close and MDI parent?

Post by RGF2ZV » Sat, 20 Sep 2008 06:06:01


I've got a situation in a VB 2003 Windows application with an MDI form and a
child form. In certain situations, when the child is closed by the user, I
also want to close the MDI parent. Is there a way to close the MDI parent
with code in the child form?

In the MDI child form, I have tried:

me.MDIParent.Close

but that doesn't appear to work. Is that because of object references in
the parent that are still alive? Is this even possible?

Thanks!
 
 
 

Can an MDI child close and MDI parent?

Post by Gillar » Sat, 20 Sep 2008 06:41:32

Form1.Close 'Form1 is the parent

 
 
 

Can an MDI child close and MDI parent?

Post by Family Tre » Sat, 20 Sep 2008 08:07:05

Gillard, Form1.Close looks like a static method call on class Form1. Is
that what you meant?

DaveP, It is possible to close the app from the child forms. I would raise
an event for the main app to handle the close operation.
 
 
 

Can an MDI child close and MDI parent?

Post by James Hah » Sat, 20 Sep 2008 08:43:35

The idea of tryng to close the parent from the child never seemed qute
proper to me. The technique I have used is for the child to change a
property of the parent as it is closing, and then to put the code to clean
up the other children and close down the parent in the change event for that
parent property. At first it seemed like a kludge, but in practice it is
very effective. Of course, you should choose a property of the parent that
the user isn't going to change. For instance, change the text of the parent
to "Closing", and put the shutdown code in the parent's textchanged event.