views:

40

answers:

1

I have a MDI application being developed using C# (VS2008). There are multiple child forms and they all seem to close when hitting the close button except for one form. And when this particular form is open the Parent form will not close either.

I am not sure what other information to provide .

Please help.

+1  A: 

Does the child form handle its FormClosing event? It could be that it handles FormClosing and sets e.Cancel = true; -- in that case, it will prevent the child form (and possibly the parent form as well) from closing.

Try adding a handler to your parent form's FormClosing event and step through the code from there -- you should be able to figure out if any of your child forms its handling its own FormClosing.

Just a guess, but worth investigating.

Dan Tao
The child form is not handling its own FormClosing, that is why I am scratching my head
mattgcon
+1 even if this turns out not to be the issue. That's where I'd start as well.
David Stratton
Ok I did add a FormClosing handler and it worked for the Child form and for the Parent form. Now the question is why is it that this particular form have to have the FormClosing handler and the other child forms did not? ***ALSO*** All of the Child forms have the same properties set.
mattgcon
@mattgcon: Just to clarify, what *happens* in your child form's `FormClosing` handler?
Dan Tao
By adding the FormClosing handler, I was able to successfully close the forms. the only line of code that is in the handler is e.Cancel = false.The only thing I am baffled by is to why the other forms closed without problems with no FormClosing handler
mattgcon
@mattgcon: The form that was giving you problems... do you not have access to its source code? It could be that code *elsewhere* added `e.Cancel = true` and it was required for you to add `e.Cancel = false` to "undo" that line. Generally you do not need to handle a form's `FormClosing` event to ensure it closes; it is only where someone has explicitly set `e.Cancel = true` that you might run into complications, as you have here.
Dan Tao