If I want FormClosing and FormClose to run am I suppose to call the forms Close method?

  • Thread starter Thread starter AAaron123
  • Start date Start date
A

AAaron123

If I show a form with ShowDialog and Dispose it FormClosing does not appear
to run.

At least I think that is true.



If I want FormClosing and FormClose to run am I suppose to call the forms
Close method?





Thanks
 
Aaron,


Have a look at the buttons settings in the properties of your child form,
mostly is the error there.

I never use that because of this reason.

Cor
 
AAaron123 said:
If I show a form with ShowDialog and Dispose it FormClosing does not
appear to run.

At least I think that is true.



If I want FormClosing and FormClose to run am I suppose to call the
forms Close method?

You should execute what you want to do, not what you expect to happen. I
mean, if you want to Close the Form, call it's Close method. So, the
answer is "yes". If you have shown it using ShowDialog, you have to call
Dispose after it has been closed. Closing and Disposing have been
seperated because you then have the opportunity to acces the controls
between closing and disposing, which is sometimes/often done with modal
Forms, and which is not (reliable) possible if it had been disposed. If
you've shown it using the Show method, the Form is automatically
disposed as a reaction of the Closed event.


Armin
 
To summarize: Disposing does not cause Closing to run.

This verifies what I thought was happing.

Thanks a lot
 
I couldn't find any button properties that appear to apply.
Which did you have in mind?

Thanks
 
AAaron123 said:
To summarize: Disposing does not cause Closing to run.

This verifies what I thought was happing.

How do you dispose the form if you are showing it by calling 'ShowDialog'?
Execution is blocked when calling 'ShowDialog' and if you are disposing the
form afterwards the form has already been closed. Did you call 'Dispose' in
a button's 'Click' event handler on the form shown by calling 'ShowDialog'?
 
Thanks for your interest.
This is an example:

Dim formModifyImage As New FormModifyImage

formModifyImage.ShowDialog() 'Gets the image from clipboard

formModifyImage.Close()

formModifyImage.Dispose()



Often there is code before formModifyImage.Close() that uses properties of
the form.

Seems to me now, that I should get a FormClosing event when the user closes
the form. Correct?

And the statement formModifyImage.Close() should have no effect. Correct?





Thanks
 
AAaron123 said:
Thanks for your interest.
This is an example:

Dim formModifyImage As New FormModifyImage

formModifyImage.ShowDialog() 'Gets the image from clipboard

formModifyImage.Close()

formModifyImage.Dispose()



Often there is code before formModifyImage.Close() that uses
properties of the form.

Seems to me now, that I should get a FormClosing event when the user
loses the form. Correct?
Correct.

And the statement formModifyImage.Close() should have no effect.
Correct?

Correct, because formModifyImage.Close() is only reached after the form
has been closed and ShowDialog returns.


Armin
 
Back
Top