Solved

MDI closing override (urgent)

Posted on 2004-09-06
4
217 Views
Last Modified: 2008-03-06
Hi Experts!  I'm on a tight deadline, so thanks for your help in advance!

I have an MDI (frmParent) with about 20 child windows.

When I close frmParent, it closed the children first.  The children have Closing events I want to check to see if the parent is closing, and if so, NOT to execute the code in the event.

The problem is I can't create a flag for the children to check because when the parent closes it closed the children first, and then it executes the Closing code in the parent.

I have not really worked with user32.dll overrides, but if someone could show me what code to put in the frmParent that would be absolutley awesome!  The goal is to have a flag the children could check before executing the Closing event.

Thanks

0
Comment
Question by:OptionsMM
  • 2
4 Comments
 
LVL 5

Expert Comment

by:jjacksn
ID: 11993869
I don't think this is true.  

If you capture the Form_Closing Event, it has to fire before the children, because you can cancel it.  Otherwise, there would be no way to warn the user to save data or something when the X is clicked without first closing all child windows.  Are you sure you are thinking about this correctly?

(you can just set a boolean in the Form_Closing Event)
0
 
LVL 12

Accepted Solution

by:
sumix earned 500 total points
ID: 11993898
Hi,

You can override WndProc method of the parent form to check if it'is closing. This function is called whenever the window receives a system message.

private const int WM_CLOSE = 0x10;
....

protected override void WndProc(ref Message m)
{
      if (m.Msg==WM_CLOSE)
      {
            MessageBox.Show("Closing...");
            // set same flag that the children can check
      }
      base.WndProc (ref m);
}


0
 

Author Comment

by:OptionsMM
ID: 11997189
jjacksn,

I am correct, the parent closing even is definitely after the child, not before

"Otherwise, there would be no way to warn the user to save data or something when the X is clicked without first closing all child windows."

that is why i need the override.

thanks sumix worked beautifully!
0
 
LVL 5

Expert Comment

by:jjacksn
ID: 11998758
OptionsMM, hmm, that's very very strange.  At any rate, glad you found a solution
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now