473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 2494
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 frmDealerSearch and put the focus on txtDealerNum on...
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 dirty and give the user an opportunity a) lose...
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 option is to convert the Login control to a...
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 application won't close properly. I can explicitly set...
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 sure he wants to close the form, because it...
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 crash. I've found various articles describing a...
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 catches its Closing event and cancels it if the...
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 form's "X" was clicked. That is, I need to know if...
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 another application that is a third-part windows...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.