Can an MDI child close and MDI parent?

  • Thread starter Thread starter DaveP
  • Start date Start date
D

DaveP

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!
 
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.
 
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.
 
Back
Top