选项卡没有选择与选定的形式更改

问题描述:

我有我的应用程序中的表格和每当我打开多个窗体的标签以常用方式打开,但每当我打开已打开的窗体选定的选项卡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

我得到的答案

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;