Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

MDI closing override (urgent)

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
OptionsMM
Asked:
OptionsMM
  • 2
1 Solution
 
jjacksnCommented:
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
 
sumixCommented:
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
 
OptionsMMAuthor Commented:
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
 
jjacksnCommented:
OptionsMM, hmm, that's very very strange.  At any rate, glad you found a solution
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now