/// <summary> /// When a different MDI child is activated, /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FormMain_MdiChildActivate(object sender, EventArgs e) { if (this.ActiveMdiChild == null) { this.tabMain.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) { MyFormPage mfp = this.ActiveMdiChild as MyFormPage; if (mfp != null) { MyTabPage newPage = new MyTabPage(mfp); this.tabMain.TabPages.Add(newPage); this.tabMain.SelectedTab = newPage; this.ActiveMdiChild.Tag = newPage; this.ActiveMdiChild.FormClosed += new FormClosedEventHandler(ActiveMdiChild_FormClosed); this.tabMain.Show(); } } else { MyTabPage mtp = this.ActiveMdiChild.Tag as MyTabPage; this.tabMain.SelectedTab = mtp; } } this.UpdateMenu(); }
/// <summary> /// Different tab is selected, change the active MDI child /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tabMain_SelectedIndexChanged(object sender, EventArgs e) { if (this.tabMain.SelectedTab != null) { MyTabPage mtp = this.tabMain.SelectedTab as MyTabPage; if (mtp != null) { mtp.m_frm.Activate(); } } }