You may wish to review Section 7.3, to get a feel for how window events fit into the lifetime of your application.
The following events are received by a window instance in connection with its lifetime:
Sent to a window instance after it comes into existence, after an Open event has been sent to each control in the window, but before the window becomes visible to the user.
Sent to a
window instance because the
process of closing it has been initiated; for how this happens, see
Section 9.2, earlier in this chapter. The
CancelClose event handler can perform last-minute activities; it can
also prevent the window from closing by returning
true. (If the application was trying to quit, this
will also prevent it from doing so; see Chapter 7.) If it returns
nothing at all, the closing of the window will proceed. Thus, for
example, the CancelClose event handler is the place for a document
window to put up its Save Changes dialog, giving the user a chance to
save or to prevent the window from closing.
Sent to a window instance just before it is destroyed. The window has
false (or nothing) from the CancelClose
event. Each control in the window has received a Close event. There
is nothing now that the window can do to prevent itself from being
The following events are received by a window instance in connection with physical alterations:
Sent to a window instance because the window has come to the front: it has been visibly instantiated, ...