public METAboltTab AddTab(string name, string label, Control control) { // WORKAROUND: one should never add tab that alrady exists // but under some weird conditions disconnect/connect // fire in the wrong order if (TabExists(name)) { Logger.Log("Force closing tab '" + name + "'", Helpers.LogLevel.Warning, client); ForceCloseTab(name); } control.Visible = false; control.Dock = DockStyle.Fill; toolStripContainer1.ContentPanel.Controls.Add(control); ToolStripButton button = (ToolStripButton)tstTabs.Items.Add(label); button.DisplayStyle = ToolStripItemDisplayStyle.ImageAndText; button.Image = null; button.AutoToolTip = false; button.Tag = name.ToLower(); button.AllowDrop = true; button.Click += new EventHandler(TabButtonClick); METAboltTab tab = new METAboltTab(instance, button, control, name.ToLower(), label); if (control is METAboltTabControl) { ((METAboltTabControl)control).METAboltTab = tab; } tab.TabAttached += new EventHandler(tab_TabAttached); tab.TabDetached += new EventHandler(tab_TabDetached); tab.TabSelected += new EventHandler(tab_TabSelected); tab.TabClosed += new EventHandler(tab_TabClosed); tab.TabHidden += new EventHandler(tab_TabHidden); tabs.Add(name.ToLower(), tab); if (OnTabAdded != null) { try { OnTabAdded(this, new TabEventArgs(tab)); } catch (Exception) { } } button.MouseDown += (msender, margs) => { if (margs.Button == MouseButtons.Middle) { if (tab.AllowClose) { tab.Close(); } else if (tab.AllowHide) { tab.Hide(); } } }; return(tab); }
private void tbtnCloseTab_Click(object sender, EventArgs e) { METAboltTab tab = selectedTab; if (tab.Merged) { return; } else if (tab.AllowClose) { tab.Close(); } else if (tab.AllowHide) { tab.Hide(); } }