By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,306 Members | 1,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,306 IT Pros & Developers. It's quick & easy.

Catching MDI Application Closing

P: n/a
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
Sep 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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

Sep 19 '05 #2

P: n/a
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


Sep 19 '05 #3

P: n/a
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



Sep 19 '05 #4

P: n/a
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



Sep 20 '05 #5

P: n/a
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


Sep 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.