472,371 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

Closing form event

In my application I need a way to distiguish between the following events:

1. When a user closes an MDI child window.
2. When the user closes the MDI parent window which subsequently closes
the MDI child window.

My application does certain logic when the user actually closes the MDI
child form by clicking the "X" in the upper right hand. My application,
however, should not execute this logic if the user closes the MDI parent. I
tried handling the Form.Closing event on the child window. The problem is,
that in both of the cases above, the sender is the MDI child
window--therefore the event handler doesn't know who actually closed the
form. More bad news for me: the MDI child Form.Closing event occurs before
the Parent Form.Closing event (so I can't set a flag or something on the
parent closing event to let the child closing events know that they should
not execute the application logic.)

What trick do I need to know about?

Thanks!
Nov 15 '05 #1
1 5642
Chris Bruce wrote:
In my application I need a way to distiguish between the following events:

1. When a user closes an MDI child window.
2. When the user closes the MDI parent window which subsequently closes
the MDI child window.

My application does certain logic when the user actually closes the MDI
child form by clicking the "X" in the upper right hand. My application,
however, should not execute this logic if the user closes the MDI parent. I
tried handling the Form.Closing event on the child window. The problem is,
that in both of the cases above, the sender is the MDI child
window--therefore the event handler doesn't know who actually closed the
form. More bad news for me: the MDI child Form.Closing event occurs before
the Parent Form.Closing event (so I can't set a flag or something on the
parent closing event to let the child closing events know that they should
not execute the application logic.)

What trick do I need to know about?


I see a way to set both handlers, Closing, and Close and utilize some
kind of global flag.

Child_Closing() {
_applicationQuit = false;
}
MainForm_Closing() {
_applicationQuit = true;
}
Child_Close() {
if (!_applicationQuit)
DoThis();
}

As soon as main form Closing event is called after any child Closing,
but before any child Close, you have a chance here to know either this
is application exit or child window close.

Probably it is also possible to achive by overriding main form's WndProc
and setting the flag if WM_QUIT has been passed.

Vadim Chekan.

Nov 15 '05 #2

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

Similar topics

1
by: **Developer** | last post by:
When I get a closing event in a MID Child form I don't know if the child form is closing or the main form is closing. Is there a way to tell? Thank
4
by: HANG LAM | last post by:
hi, How do I capture the closing events coming from the 'X' icon in the top-right corner of a form and the Form.Close() command? I want to be able to differentiate between the Closing Event...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
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: Sumit | last post by:
HI.. I am having problem ot determine that a parent form is closing or not in my VB.Net code Any help Sumit
2
by: Tom | last post by:
How is the best way to avoid validation when closing a window? For instance, I have a Windows Forms window which has a validation event for a text box. However, if one enters invalid data in then...
4
by: Academic | last post by:
Does it make sense to put this If e.Cancel Then Exit Sub at the beginning of form closing events so if the user cancels the app's exiting in one Closing routine he will not be asked again by...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
19
by: zacks | last post by:
I have a .NET 2.0 MDI application where the child form has a Tab Control. Each of the Tab in the Tab Control has a Validating event to handle what it should do when the user changes tabs. But...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.