消除可能重复的MDIChildren

时间:2014-12-28 20:11:44

标签: c# duplicates mdichild

我的代码有什么问题可以防止MDI子代复制???

//Create a new instance of the MDI child template form
FAnalysis fanalysis = null;
if (fanalysis != null)
{
    fanalysis.WindowState = FormWindowState.Normal;
    fanalysis.Focus();
}
else
{
    fanalysis = new FAnalysis();
    fanalysis.MdiParent = this;
    //Display the child window
    fanalysis.Show();
    changeVisible(false, false, true, true, true, true);
 }

任何帮助都会被感染...谢谢

1 个答案:

答案 0 :(得分:1)

我会做类似的事情:

        foreach(Form child in this.MdiChildren)
        {
            if (child is FAnalysis)
            {
                if (child.WindowState == FormWindowState.Minimized)
                {
                    child.WindowState = FormWindowState.Normal;
                }
                child.BringToFront();
                return; // stop looking and exit the method
            }
        }

        // no match was found; create a new child:
        FAnalysis fanalysis = new FAnalysis();
        fanalysis.MdiParent = this;
        fanalysis.Show();
        changeVisible(false, false, true, true, true, true);
相关问题