简体   繁体   中英

Sequence of events during form close event in vb.net

Trying to understand how best to handle a closing event.

If I have multiple workspaces open that have children that when closed, may return data to the parent, which may mean the parent needs to process something, I am trying to figure the best way to stop the closing and return control to the parent workspace. (I can open different workspaces and have windows that are basically modal to the parent workspace.)

For Example: I have an account workspace that calls an address edit window. I close the app (from the window hosting the account workspace) in the middle of an address edit. I have the closing event step through the workspaces and if it finds a modal window open, it executes the canclose on that windows workspace.

Let's say the canclose prompts for a save and close, exit no save or cancel close. If it is save, the modal workspace sends the address back to the account workspace, which processes it. This usually leads to not continuing the close as this new data needs to be examined in relation to the account workspace and possibly saved there. I want the account workspace to take focus and I want the canclose that was initiated to get a false return.

Should I do the focus on the workspace as an event and just return false to the calling canclose?

I am confused on what happens sequence wise when I am running a process such as canclose and I fire an event off as to when the event code will actually execute in relation to the code that asked for the event.

Instead of using your own mechanism (and possibly re-inventing the wheel), please first consider native FormClosing event. There you can Cancel closing or override CloseReason to a custom, non-cascaded value, for more a granular action tree.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM