2012-03-11 111 views
0

我有我的應用程序中的表格和每當我打開多個窗體的標籤以常用方式打開,但每當我打開已打開的窗體選定的選項卡doesnt得到changed.it獲取卡在最後打開的標籤上。我的代碼在這裏。選項卡沒有選擇與選定的形式更改

private void Form1_MdiChildActivate(object sender, EventArgs e) 
    { 
     if (this.ActiveMdiChild == null) 
      tabForms.Visible = false; 
     // If no any child form, hide tabControl 
     else 
     { 
      this.ActiveMdiChild.WindowState = FormWindowState.Maximized; 
      // Child form always maximized 

      // If child form is new and no has tabPage, 
      // create new tabPage 
      if (this.ActiveMdiChild.Tag == null) 
      { 
       // Add a tabPage to tabControl with child 
       // form caption 

       TabPage tp = new TabPage(this.ActiveMdiChild.Text); 
       tp.Tag = this.ActiveMdiChild; 
       tp.Parent = tabForms; 
       tabForms.SelectedTab = tp; 


       SwapTabPages(tp); 

       this.ActiveMdiChild.Tag = tp; 
       this.ActiveMdiChild.FormClosed += new FormClosedEventHandler(ActiveMdiChild_FormClosed); 
      } 

      if (!tabForms.Visible) tabForms.Visible = true; 

     } 
    } 


private void ActiveMdiChild_FormClosed(object sender, FormClosedEventArgs e) 
    { 
     //Destroy the corresponding Tabpage when closing MDI child form 
     if (tabForms.HasChildren) 
     { 
      ((sender as Form).Tag as TabPage).Dispose(); 
     }    
     //If no Tabpage left 
     else if (!tabForms.HasChildren) 
     { 
      tabForms.Visible = false;     
     }    
    } 

    private void tabForms_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     if ((tabForms.SelectedTab != null) && (tabForms.SelectedTab.Tag != null)) 
      (tabForms.SelectedTab.Tag as Form).Select();    
    } 
+1

這不是一個問題。這是一個可笑的長時間的逃避判決。 – abelenky 2012-03-11 02:36:41

回答

0

我得到的答案

else 
       { 

        for (int i = 0; i < tabForms.TabCount; i++) 
         { 
          if (tabForms.TabPages[i].Text == this.ActiveMdiChild.Text.ToString()) 
           { 
            tabForms.SelectedTab = tabForms.TabPages[i]; 
              break; 
           } 
         } 
       }     
       if (!tabForms.Visible) tabForms.Visible = true; 
相關問題