Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# MDI Parent detect when MDI Child is closing?

I'm attempting to detect, on the MDI parent, when my MDI child form closes, and react accordingly. The MDI parent shouldn't do anything until the MDI child closes. Here is my code, I'm unsure as to what I'm doing wrong, but the form closed event method I added is never being called...

The following code is in the MDI parent class, if that wasn't obvious.

    private void keyValidation()
    {
        if (Properties.Settings.Default.Unlock == true)
            return;
        else
        {
            menu.Enabled = false;
            statusStrip.Enabled = false;

            ValidationForm vf = new ValidationForm();
            vf.MdiParent = this;
            vf.Show();
            vf.FormClosed += new FormClosedEventHandler(validationForm_FormClosed);
        }
    }

    void validationForm_FormClosed(object sender, FormClosedEventArgs e)
    {
        MessageBox.Show("Got here");
        if (Properties.Settings.Default.Unlock == true)
        {
            menu.Enabled = true;
            statusStrip.Enabled = true;
        }
    }

Thanks for any help!

like image 593
CODe Avatar asked Dec 06 '10 15:12

CODe


1 Answers

While this doesn't really address the problem you're referring to, judging from the use case, you may want to consider opening the Validation form as a modal dialog instead of as an MDI child.

You can do this using the form's ShowDialog() method where you have Show() now. Keep in mind that ShowDialog() can also return a DialogResult if you assign them to buttons on the other form.

like image 160
Powerlord Avatar answered Oct 11 '22 00:10

Powerlord