Solved

MDI closing override (urgent)

Posted on 2004-09-06
4
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

630 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