2014-12-28 11 views
0

MDI 자식 중복을 방지하기 위해 내 코드에 어떤 문제가 있습니까 ???가능한 중복 MDIChildren 제거

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

도움이 Appretiated 것 ... 감사

+0

어떻게 로컬 변수가 null이 될 수 없습니다하는 기대를? – SLaks

+0

'fanalysis = new FAnalysis();' –

+0

_local_ 변수입니다. 모든 통화마다 다릅니다. – SLaks

답변

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