473,467 Members | 1,604 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Catching MDI Application Closing

I have an MDI application with a number of child windows. In each child
window I am catching the Closing event and having the child window decide if
it should set cancel to true. The intent here is to ensure that no child
window can close while it is in a state where user entered information can
be lost. I have just noticed that while the Closing event is caught if I
click the X on the child window, it is not caught if I click the X on the
MDI parent window. Is there some other event that I am missing here?

Thanks,
Ron L
Nov 21 '05 #1
5 1177
Hi,

What about:

mainMID.Closing += new
System.ComponentModel.CancelEventHandler(this.Wind ow_Closing);

private void Window_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// Loop all childs and see if can close or save or ... do what you need
foreach(Form frm in this.MdiChildren){
}
}

At least this works ok for me.

"Ron L" <ro**@bogus.Address.com> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
I have an MDI application with a number of child windows. In each child
window I am catching the Closing event and having the child window decide
if it should set cancel to true. The intent here is to ensure that no
child window can close while it is in a state where user entered
information can be lost. I have just noticed that while the Closing event
is caught if I click the X on the child window, it is not caught if I click
the X on the MDI parent window. Is there some other event that I am
missing here?

Thanks,
Ron L

Nov 21 '05 #2
Ivar

Thanks for the response, I'll give it a try. Do you know why the Closing
event on the child windows only get thrown when the child window is closed
directly? I had thought that they would be thrown for any cause of the
window closing.

Ron L
"Ivar" <iv*@lumisoft.ee> wrote in message
news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi,

What about:

mainMID.Closing += new
System.ComponentModel.CancelEventHandler(this.Wind ow_Closing);

private void Window_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// Loop all childs and see if can close or save or ... do what you need
foreach(Form frm in this.MdiChildren){
}
}

At least this works ok for me.

"Ron L" <ro**@bogus.Address.com> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
I have an MDI application with a number of child windows. In each child
window I am catching the Closing event and having the child window decide
if it should set cancel to true. The intent here is to ensure that no
child window can close while it is in a state where user entered
information can be lost. I have just noticed that while the Closing event
is caught if I click the X on the child window, it is not caught if I
click the X on the MDI parent window. Is there some other event that I am
missing here?

Thanks,
Ron L


Nov 21 '05 #3
hild window is closed
directly? How you close window (I mean not dircetly)?
(Are you hidding or closing !)

"Ron L" <ro**@bogus.Address.com> wrote in message
news:eO**************@tk2msftngp13.phx.gbl... Ivar

Thanks for the response, I'll give it a try. Do you know why the Closing
event on the child windows only get thrown when the child window is closed
directly? I had thought that they would be thrown for any cause of the
window closing.

Ron L
"Ivar" <iv*@lumisoft.ee> wrote in message
news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi,

What about:

mainMID.Closing += new
System.ComponentModel.CancelEventHandler(this.Wind ow_Closing);

private void Window_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// Loop all childs and see if can close or save or ... do what you
need
foreach(Form frm in this.MdiChildren){
}
}

At least this works ok for me.

"Ron L" <ro**@bogus.Address.com> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
I have an MDI application with a number of child windows. In each child
window I am catching the Closing event and having the child window decide
if it should set cancel to true. The intent here is to ensure that no
child window can close while it is in a state where user entered
information can be lost. I have just noticed that while the Closing
event is caught if I click the X on the child window, it is not caught if
I click the X on the MDI parent window. Is there some other event that I
am missing here?

Thanks,
Ron L



Nov 21 '05 #4
Ivar

I am closing the application, and all of its child windows, by clicking on
the "X" or Form.Close on the MDI Parent form. I had thought that the
application closing would fire a Closing event to each of the child windows,
but this is apparently not happening.

Thanks,
Ron L
"Ivar" <iv*@lumisoft.ee> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
hild window is closed
directly?

How you close window (I mean not dircetly)?
(Are you hidding or closing !)

"Ron L" <ro**@bogus.Address.com> wrote in message
news:eO**************@tk2msftngp13.phx.gbl...
Ivar

Thanks for the response, I'll give it a try. Do you know why the Closing
event on the child windows only get thrown when the child window is
closed directly? I had thought that they would be thrown for any cause
of the window closing.

Ron L
"Ivar" <iv*@lumisoft.ee> wrote in message
news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi,

What about:

mainMID.Closing += new
System.ComponentModel.CancelEventHandler(this.Wind ow_Closing);

private void Window_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// Loop all childs and see if can close or save or ... do what you
need
foreach(Form frm in this.MdiChildren){
}
}

At least this works ok for me.

"Ron L" <ro**@bogus.Address.com> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
I have an MDI application with a number of child windows. In each child
window I am catching the Closing event and having the child window
decide if it should set cancel to true. The intent here is to ensure
that no child window can close while it is in a state where user entered
information can be lost. I have just noticed that while the Closing
event is caught if I click the X on the child window, it is not caught
if I click the X on the MDI parent window. Is there some other event
that I am missing here?

Thanks,
Ron L



Nov 21 '05 #5
Ivar

I tried the loop you suggested, but I still don't seem to be able to catch
the cancel from the individual windows closing to be able to keep the
application from exiting. Do you have any suggestions on this?

Here is my close handler:
' 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
MessageBox.Show("Exiting the app!")
For Each frm As Form In _mainView.MdiChildren
frm.Close()
Next
End Sub

Thanks,
Ron L
"Ivar" <iv*@lumisoft.ee> wrote in message
news:uK**************@TK2MSFTNGP10.phx.gbl...
Hi,

What about:

mainMID.Closing += new
System.ComponentModel.CancelEventHandler(this.Wind ow_Closing);

private void Window_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// Loop all childs and see if can close or save or ... do what you need
foreach(Form frm in this.MdiChildren){
}
}

At least this works ok for me.

"Ron L" <ro**@bogus.Address.com> wrote in message
news:uu**************@TK2MSFTNGP10.phx.gbl...
I have an MDI application with a number of child windows. In each child
window I am catching the Closing event and having the child window decide
if it should set cancel to true. The intent here is to ensure that no
child window can close while it is in a state where user entered
information can be lost. I have just noticed that while the Closing event
is caught if I click the X on the child window, it is not caught if I
click the X on the MDI parent window. Is there some other event that I am
missing here?

Thanks,
Ron L


Nov 21 '05 #6

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

Similar topics

3
by: Wortelvisje | last post by:
Hello, What I want to do is quit simple: if the does clicks on the cross at the right top of the screen I want to catch this event and check a few things before closing the window. The only...
5
by: Ron L | last post by:
I have an MDI application with a number of child windows. In each child window I am catching the Closing event and having the child window decide if it should set cancel to true. The intent here...
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...
3
by: Elp | last post by:
Hi, I've developped a Window Form C# application which main form contains several activex controls. No problems most of the time but on some machine, the application crashes when the main form...
2
by: Silby | last post by:
Hi, I've a form.load event that initializes a cardreader, which is crucial to the operating of the program. Now if that throws an exception, the program needs to give a message and close down....
5
by: lord.zoltar | last post by:
How can I prevent the big close button in the top of the window from closing the window? I want to have and "are you sure?" confirmation so the user must press "Yes" before the program ends. Right...
5
by: Sam Samson | last post by:
Hi All, I have seen a few good behaviours for what to do in the case of those pesky uncaught exceptions. and I want to build some of these mechanisms into my Application that is currently out on...
3
by: Anthony P. | last post by:
Hello Everyone, I am writing a Windows Mobile 5.0 application using VS 2..8 in VB.NET. When someone clicks the "Exit" menu option, which generates a button_click() event, I find it easy to...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
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
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
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.