472,331 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

How to cancel MDI Application Closing from child windows

I have an MDI application which opens a number of child windows, each of
which could have data in a state that needs to be saved. Each child window
catches its Closing event and cancels it if the user wants to save the data,
but when the Application closes this event isn't thrown automatically. I
added a loop to close each child window, but can't seem find how to catch
the child window's cancel of the Closing event, so even if the user selects
cancel to the closing event the application closes anyway. Can anyone point
me in the right direction here?

Here is my application closing handler which closes each child window:
' Catch the application exit event and gracefully close all MDI child
windows
Private Sub ApplicationExiting(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.CancelEventArgs)

Handles _mainView.Closing
For Each frm As Form In _mainView.MdiChildren
frm.Close()
Next
End Sub

TIA
Ron L

P.S. sorry for the cross-post, I forgot to add these groups before I clicked
send. DOH!
Sep 26 '05 #1
2 2395
There are a couple of things you can do, and it is up to you how you
implement them.

My recommendations

First: Do not issue the Application.Exit or Application.End until after all
your child forms are closed and all state data is preserved.

Second: On _mainView_Closing count the number of opened mdichildren and
set e.Cancel = true if the number is greater than 0

Third: Move your Application.End or Application.Exit statement in either
_mainView.Closed or more remote location.
sample:

sub _mainView_Closing

for each f as form in _mainView.mdichildren
f.close
next

if _mainView.mdichildren.length > 0 then e.cancel = true

end sub

sub _mainView_Closed
End
end sub
"Ron L" <ro**@bogus.Address.com> wrote in message
news:OM**************@TK2MSFTNGP14.phx.gbl...
I have an MDI application which opens a number of child windows, each of
which could have data in a state that needs to be saved. Each child
window
catches its Closing event and cancels it if the user wants to save the
data,
but when the Application closes this event isn't thrown automatically. I
added a loop to close each child window, but can't seem find how to catch
the child window's cancel of the Closing event, so even if the user
selects
cancel to the closing event the application closes anyway. Can anyone
point
me in the right direction here?

Here is my application closing handler which closes each child window:
' Catch the application exit event and gracefully close all MDI child
windows
Private Sub ApplicationExiting(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.CancelEventArgs)

Handles _mainView.Closing
For Each frm As Form In _mainView.MdiChildren
frm.Close()
Next
End Sub

TIA
Ron L

P.S. sorry for the cross-post, I forgot to add these groups before I
clicked send. DOH!

Sep 27 '05 #2
AMDRIT

Thank you for your response. It worked great! I had been trying to pass on
the cancel rather than just see if anything canceled after the fact.

Ron L

"AMDRIT" <am****@hotmail.com> wrote in message
news:ej**************@TK2MSFTNGP12.phx.gbl...
There are a couple of things you can do, and it is up to you how you
implement them.

My recommendations

First: Do not issue the Application.Exit or Application.End until after
all your child forms are closed and all state data is preserved.

Second: On _mainView_Closing count the number of opened mdichildren and
set e.Cancel = true if the number is greater than 0

Third: Move your Application.End or Application.Exit statement in either
_mainView.Closed or more remote location.
sample:

sub _mainView_Closing

for each f as form in _mainView.mdichildren
f.close
next

if _mainView.mdichildren.length > 0 then e.cancel = true

end sub

sub _mainView_Closed
End
end sub
"Ron L" <ro**@bogus.Address.com> wrote in message
news:OM**************@TK2MSFTNGP14.phx.gbl...
I have an MDI application which opens a number of child windows, each of
which could have data in a state that needs to be saved. Each child
window
catches its Closing event and cancels it if the user wants to save the
data,
but when the Application closes this event isn't thrown automatically. I
added a loop to close each child window, but can't seem find how to catch
the child window's cancel of the Closing event, so even if the user
selects
cancel to the closing event the application closes anyway. Can anyone
point
me in the right direction here?

Here is my application closing handler which closes each child window:
' Catch the application exit event and gracefully close all MDI child
windows
Private Sub ApplicationExiting(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.CancelEventArgs)

Handles _mainView.Closing
For Each frm As Form In _mainView.MdiChildren
frm.Close()
Next
End Sub

TIA
Ron L

P.S. sorry for the cross-post, I forgot to add these groups before I
clicked send. DOH!


Sep 28 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Mike L | last post by:
I have a child form frmDataEntry call up another child form frmDealerSearch. If the user clicks on cancel on frmDealerSearch, I want to close...
0
by: JerryK | last post by:
Hi, I have an MDI application. If the user presses the close button (the X in the upper right), I need to check each child form and see if it is...
14
by: clintonG | last post by:
This is an appeal for peer support sent to Microsoft as will be noted in closing. The Login control does not include a Cancel button. The only...
3
by: Charles Law | last post by:
Under what circumstances would e.Cancel be set to True on entry to the Closing event of an MDI child form? I have found that this is why my...
3
by: Oenone | last post by:
I'm writing an application with various MDI child forms. In the Closing event of many of the forms, I have code that asks the user whether he is...
5
by: Sam Loveridge | last post by:
Hi All. I'm hoping someone can point me in the direction of a solution to unhandled exceptions in MDI child forms causing the application to...
2
by: Ron L | last post by:
I have an MDI application which opens a number of child windows, each of which could have data in a state that needs to be saved. Each child window...
6
by: **Developer** | last post by:
I've been looking but can't find out how in a form Closing event to know if the closing is because the form's "X" had been clicked or the main...
3
by: asadikhan | last post by:
Hi, I have written a windows application with a GUI (let's call it MENU). I own the code for this application and have access to it. We have...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.