VB6 - Which event is invoked by the X button?
I would like to activate a piece of code in my MDI form when the red X button at the upper right is clicked (I don't know what it is officially called) so that the program closes down nicely.
What method in the Form is in开发者_高级运维voked when that happens?
Form_QueryUnload
is called. Since you have indicated an MDI application, the exact event invoked is
Private Sub MDIForm_QueryUnload(cancel As Integer, unloadmode As Integer)
where if you set cancel
to a non-zero value inside this function, it stops the application from exiting. In other words, QueryUnload
is a way to query if the form should unload or not. The second argument, unloadmode
gives you the information how this unloading was triggered.
More help on MSDN.
Using the Unload and QueryUnload Events in an MDI Application
When you attempt to unload the main MDI form in an MDI application, VB unloads all the open Child forms first. This means that the various Unload and QueryUnload events have a special timing relationship in an MDI application. When there is an attempt to unload the main MDI form, the order of the Unload and QueryUnload events is as follows:
1.The MDI form's
QueryUnload
event
2.TheQueryUnload
event of each open Child form
3. TheUnload
event of each Child form
4. TheUnload
event of the MDI formIf Cancel is set to True within any of these event procedures, the entire unloading process stops. If unloading is halted during any of the QueryUnload event procedures, then none of the Unload events is triggered, and no form is unloaded. If unloading is halted during any of the Unload event procedures, then only forms whose Unload events happened before the one where the Cancel occurred will unload.
精彩评论