Question

I have MDI parent form. Under this MDI Parent there are lots of MDI Child form. How I check child form are open or not?

            foreach (Form frm in this.MdiChildren)
            {
                if (frm == null)
                {
                   //code.....
                }
            }

But this is not working.

Was it helpful?

Solution

Once you close the child forms, they should drop out of the MdiChildren collection.

So you can just use this:

if (!MdiChildren.Any())
{
    // all child forms closed
}

If you've just hidden the child forms, not closed them, you can use:

if (MdiChildren.All(c => !c.Visible))
{
    // all child forms hidden/closed
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top