473,714 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ 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 ApplicationExit ing(ByVal sender As System.Object, _
ByVal e As System.Componen tModel.CancelEv entArgs)

Handles _mainView.Closi ng
For Each frm As Form In _mainView.MdiCh ildren
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 2519
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.Exi t or Application.End until after all
your child forms are closed and all state data is preserved.

Second: On _mainView_Closi ng 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.Exi t statement in either
_mainView.Close d or more remote location.
sample:

sub _mainView_Closi ng

for each f as form in _mainView.mdich ildren
f.close
next

if _mainView.mdich ildren.length > 0 then e.cancel = true

end sub

sub _mainView_Close d
End
end sub
"Ron L" <ro**@bogus.Add ress.com> wrote in message
news:OM******** ******@TK2MSFTN GP14.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 ApplicationExit ing(ByVal sender As System.Object, _
ByVal e As System.Componen tModel.CancelEv entArgs)

Handles _mainView.Closi ng
For Each frm As Form In _mainView.MdiCh ildren
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******** ******@TK2MSFTN GP12.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.Exi t or Application.End until after
all your child forms are closed and all state data is preserved.

Second: On _mainView_Closi ng 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.Exi t statement in either
_mainView.Close d or more remote location.
sample:

sub _mainView_Closi ng

for each f as form in _mainView.mdich ildren
f.close
next

if _mainView.mdich ildren.length > 0 then e.cancel = true

end sub

sub _mainView_Close d
End
end sub
"Ron L" <ro**@bogus.Add ress.com> wrote in message
news:OM******** ******@TK2MSFTN GP14.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 ApplicationExit ing(ByVal sender As System.Object, _
ByVal e As System.Componen tModel.CancelEv entArgs)

Handles _mainView.Closi ng
For Each frm As Form In _mainView.MdiCh ildren
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
2319
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 frmDataEntry. Here is my code. public class frmDataEntry : System.Windows.Forms.Form { private void txtDealerNum_Leave(object sender, System.EventArgs e) {
0
1062
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 their changes, b) save changes and continue closing, or c) abort the close action. I have code that presents these choices and does the correct thing from the MDI child's point of view, but I am search for a mechanism for notifying the MDI parent...
14
2626
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 template which is not such a bad thing in itself but it means all other controls in the application must also be converted to templates to maintain a consistent UI. So much for writing 70% less code when foolish morons release a control with no cancel...
3
2773
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 the value to False, but I would have expected it to be False on entry. TIA Charles
3
6369
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 contains unsaved data. If the user clicks "No" then the code sets e.Cancel = True, which cancels the closure. This works just great. But when the user closes the MDI parent form, the cancellation seems to be completely ignored. The MessageBox...
5
4541
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 method using Application.Run(new MyMainParentForm) to place in the application's Sub Main to allow catching of unhandled exceptions in the application. The problem I'm facing is that I want to be able to trap unhandled exceptions at the MDI child...
2
1145
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 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...
6
1675
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 just the form is closing or the application is closing. Do you know how to tell?
3
2690
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 application with a GUI interface as well (let's call it BASE). I don't have access to the code of this application. This application has hooks through which other applications can be called. I have defined a hook in this application which bring up...
0
8796
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9307
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9170
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6627
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5943
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4462
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4715
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2105
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.