2014-10-31 17 views
0
  • 假設有多於3個子表單作爲 Can_ListCandidate和其他一些表單打開。每當我點擊一個 按鈕,所有Can_ListCandidate表單將被關閉。

我試過下面的代碼,但它沒有工作。如何使用C關閉所有定義的子表單#

Can_ListCandidate frm = new Can_ListCandidate(); 

foreach (Form f in this.MdiChildren) 
{ 
    if (f == frm) 
    { 
     frm.Dispose(); 
     return; 
    } 
} 

Can_ListCandidate frm = new Can_ListCandidate(); 

foreach (Form f in this.MdiChildren) 
{ 
    if (f is Can_ListCandidate) 
    { 
     frm.Dispose(); 
     return; 
    } 
} 
+4

''==是指涉平等。我想你想做'f是Can_ListCandidate'。 – 2014-10-31 14:49:33

+0

這可能有助於發佈一些更多的代碼。 – 2014-10-31 16:15:18

回答

1
foreach (Form frm in this.MdiChildren) 
{ 
     if (frm.GetType() == typeof(Can_ListCandidate)) 
     { 
      frm.Dispose(); 
      //return; 
     } 
} 
2
if (f.GetType() == typeof(Can_ListCandidate)) 
相關問題