// ********************************* // Message from Original Author: // // 2008 Jose Menendez Poo // Please give me credit if you use this code. It's all I ask. // Contact me for more info: menendezpoo@gmail.com // ********************************* // // Original project from http://ribbon.codeplex.com/ // Continue to support and maintain by http://officeribbon.codeplex.com/ using System.Windows.Forms.Classes.Collections; namespace System.Windows.Forms { /// /// Represents a collection of RibbonTab objects /// public sealed class RibbonTabCollection : RibbonCollectionBase { /// /// Creates a new RibbonTabCollection /// /// | /// owner is null internal RibbonTabCollection(Ribbon owner) : base(owner) { if (owner == null) throw new ArgumentNullException("owner"); } internal override void SetOwner(RibbonTab item) { item.SetOwner(Owner); } internal override void ClearOwner(RibbonTab item) { item.ClearOwner(); } internal override void UpdateRegions() { try { Owner.OnRegionsChanged(); } catch { // ignored } } /// /// Removes the tab from the collection. /// /// tab to remove public new bool Remove(RibbonTab tab) { /* If the tab being deleted is the active tab, then another tab needs to be selected * to prevent errors. */ if (tab == Owner.ActiveTab) { if (Owner.Tabs.IndexOf(tab) > 0) { // This is not the first tab, make the tab preceeding this one active. Owner.ActiveTab = Owner.Tabs[Owner.Tabs.IndexOf(tab) - 1]; Owner.Tabs.Remove(tab); } else if (Owner.Tabs.IndexOf(tab) < Owner.Tabs.Count - 1) { // This is not the last tab , make the tab following this tab active. Owner.ActiveTab = Owner.Tabs[Owner.Tabs.IndexOf(tab) + 1]; Owner.Tabs.Remove(tab); } } return base.Remove(tab); } } }