0

我有一个 mdi 应用程序。我在父级上有一些链接,当单击时打开一个新的子表单并隐藏已经打开的表单 如何检查孩子是否已经打开?

A little scenario:  
link 1 -> opens Child of type A  
link 2 -> opens Child of type B  
link 3 -> open Child of type C  

Application start:  
click on link 1-> check if a child of type A is opened 

 - yes -> hides the current opened child and shows the A-type Child
 - no: -> hides the current opened child and creates a new A-type child and shows it  

click on link 2 -> check if a child of type B is opened  

 - yes -> hides the current opened child and shows the B-type Child  
 - no: -> hides the current opened child and creates a new A-type child and shows it

etc..

你能帮我一些代码吗?
谢谢...

更新:
像这样的东西?

 foreach (Form aForm in this.MdiChildren)
            {
                aForm.Hide();
            }
        foreach (Form f in this.MdiChildren)
        {
            if (f.Name == "VizualizareArticol")
                f.Show();
            else
            {
                VizualizareArticol vv = new VizualizareArticol();
                vv.MdiParent = this;
                vv.StartPosition = FormStartPosition.Manual;
                vv.Location = new Point(0, 0);

                vv.Show();
            }
        }

但不起作用...

4

1 回答 1

0

检查 Control.Visible。如果 Item 是可见的,你可以 .Hide 它,如果它不是 Visible 。否则,请查看您创建的对象。

如果您已经创建了一个表单并隐藏了它,它就会变得不可见。因此,您可以检查 .Visible 并显示表单。

if(null != aForm  && !aForm.Visible){
    aForm.Show() 
    aForm.BringToFront();
}else if(null == aForm){
    // create the form
}
// otherwise form is existing & visible
于 2013-03-21T14:18:55.533 回答