473,466 Members | 1,408 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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!
Nov 21 '05 #1
2 1136
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!

Nov 21 '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!


Nov 21 '05 #3

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

Similar topics

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...
1
by: Eric W. Holzapfel | last post by:
Hello C#, I am trying to create an MDI app in C# (Windows Application). I have a "container" window. I would like to add more than one child window to the container (2 for starters). I would...
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...
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: 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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.