Why is e.Cancel set to True on Entry to Closing Event?

  • Thread starter Thread starter Charles Law
  • Start date Start date
C

Charles Law

Under what circumstances would e.Cancel be set to True on entry to the
Closing event of an MDI child form?

I have found that this is why my application won't close properly. I can
explicitly set the value to False, but I would have expected it to be False
on entry.

TIA

Charles
 
Charles Law said:
Under what circumstances would e.Cancel be set to True on entry to the
Closing event of an MDI child form?

I have found that this is why my application won't close properly. I can
explicitly set the value to False, but I would have expected it to be False
on entry.

TIA

Charles

If a control has CausesValidation set to True, and in its Validating event
it sets e.Cancel to True, you will see this. MS calls this inability to
close the form "by design".

Best Regards,
Andy
 
Hi Andy

Thanks for the response.

I haven't deliberately implemented any Validating event, but I will,
nevertheless, check this out as a possible cause.

Cheers.

Charles
 
I have investigated this further, and can confirm that I have not
implemented any Validating event code.

So, I am still left with the same question: What would cause e.Cancel to be
True on entry to the Closing event of an MDI child form.

As I stated before, I can set this to False on exit from the event, but that
only works when there is a child form open.

What seems to happen is that when there is no child form open, I cannot
close my app because Cancel is set to True - for some reason - and there is
no child form Closing event for me to set it False.

The scenario is this:

I start my app, which opens an MDI form.
I open an MDI child form and drag some user controls onto it.
I close the MDI child form.
The Closing event fires and e.Cancel is False on entry
I open another child form and drag some user controls onto it
I click the close button on the MDI _parent_ form
The Closing event fires for the MDI child form and e.Cancel is *True* on
entry

Can anyone suggest what could cause e.Cancel to be True in this situation?

This is a particular problem when I close the second MDI child form with its
close button. Then there are no child forms open, and when I click the close
button for the MDI parent form nothing happens. The form will not close,
because (I suspect) that it has Cancel set to True internally, and therefore
abandons the close immediately.

Charles
 
Back
Top