2013-03-21 119 views
0

我有一個應用程序與mdi。我有父母的一些鏈接,當點擊打開一個新的兒童窗體並隱藏已經打開的窗口 如何檢查孩子是否已經打開?隱藏/顯示MdiChilds

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.. 

請問你能用一些代碼嗎?
謝謝...

UPDATE:
這樣的事情?

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(); 
      } 
     } 

但不工作...

回答

0

檢查Control.Visible。如果項目是可見的,你可以。隱藏它,如果它不可見。否則看看你創建的對象。

如果您已經創建了一個表單並隱藏了它,它就變得不可見。因此,您可以檢查.Visible並顯示錶單。

if(null != aForm && !aForm.Visible){ 
    aForm.Show() 
    aForm.BringToFront(); 
}else if(null == aForm){ 
    // create the form 
} 
// otherwise form is existing & visible 
+0

不理解你說的想法 – 2013-03-21 14:23:37

+0

如果你用aForm隱藏一個表單,隱藏它是不可見的。因此,如果(aForm!= null),您可以檢查是否(!aForm.Visible) – Offler 2013-03-21 16:11:26