tangxu
2024-12-24 91105b77c916d06dd30380e20594e29f85eae3da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// *********************************
// 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
{
    /// <summary>
    /// Represents a collection of RibbonTab objects
    /// </summary>
    public sealed class RibbonTabCollection
           : RibbonCollectionBase<RibbonTab>
    {
 
        /// <summary>
        /// Creates a new RibbonTabCollection
        /// </summary>
        /// <param name="owner">|</param>
        /// <exception cref="ArgumentNullException">owner is null</exception>
        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
            }
        }
 
        /// <summary>
        /// Removes the tab from the collection.
        /// </summary>
        /// <param name="tab">tab to remove</param>
        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);
        }
 
    }
}