It seems to me that the Form.Closing event can be used only in certain limited situations, such as, for example, a request to confirm the closure of a program or something similar. But in various lessons, in different examples, and in other source codes of programs, I almost always meet with Form.Closing, and never Form.Closed.

I do not understand something?

I, as a beginner, by their example also thrust everything into Form.Closing, and, as a result, the program now indecently hangs up for a second before closing, executing a different code.

enter image description here

  • 3
    Hmm, it’s pretty obvious that in Closing must be a code, as a result of which you may find out that you don’t need to close the form. +1 for a creative picture. - Igor
  • 3
    Who knows how - he does. Who does not know how to do - that manages. Who does not know how to lead - he teaches. Lessons, examples and tutorials write the last ... - Alexander Petrov
  • 3
    @AlexanderPetrov in fact, we are also learning here ... :) - MihailPw
  • one
    The fact that the program is not displayed does not mean that it does not work. The user can click on the cross and, having made sure that the program is closed, pull the computer out of the power supply network, while the program has not yet finished working with the data. Data will be corrupted. Of course, it all depends on the situation and tasks. In any case, I have not met official recommendations on the use of Closing and Closed . Therefore, I believe that the question gives rise to endless debates and discussions, and the answers will be based not on knowledge, but on the opinions of the authors. - Dmitry

1 answer 1

As a rule, in Form.Closing there is logic related to checking for closing the window itself. Ie the logic that checks the authorization, or asks for confirmation, or something else. Logic that can affect whether to allow the window to close.

In Form.Closed must be logic that either disputes something or prepares data for external use, etc. In general, all the rest is necessary when closing the window.

It is also worth noting that you can not take any video tutorials on youtube as due. They write a quick code in a quick fix.