예제 #1
0
        /// <summary>
        /// Creates new Rendering Tab at specified position, creates new associated panel and adds them to the control.
        /// </summary>
        /// <param name="text">Specifies the text displayed on the tab.</param>
        /// <param name="name">Specifies the name of the tab</param>
        /// <param name="insertPosition">Specifies the position of the new tab inside of Items collection.</param>
        /// <returns>New instance of the RibbonTabItem that was created.</returns>
        public RibbonTabItem CreateRibbonTab(string text, string name, int insertPosition)
        {
            RibbonTabItem item = new RibbonTabItem();
            item.Text = text;
            item.Name = name;

            RibbonPanel panel = new RibbonPanel();
            panel.Dock = DockStyle.Fill;
            panel.Width = this.Width - 4;
            SetRibbonPanelStyle(panel);
            this.Controls.Add(panel);
            panel.SendToBack();

            item.Panel = panel;
            if (insertPosition < 0)
            {
                insertPosition = this.Items.Count;
                for (int i = 0; i < this.Items.Count; i++)
                {
                    if (this.Items[i].ItemAlignment == eItemAlignment.Far)
                    {
                        insertPosition = i;
                        break;
                    }
                }
                if (insertPosition >= this.Items.Count)
                    this.Items.Add(item);
                else
                    this.Items.Insert(insertPosition, item);
            }
            else if (insertPosition > this.Items.Count - 1)
            {
                // Make sure we obey any items aligned to far
                insertPosition = this.Items.Count;
                for (int i = 0; i < this.Items.Count; i++)
                {
                    if (this.Items[i].ItemAlignment == eItemAlignment.Far)
                    {
                        insertPosition = i;
                        break;
                    }
                }
                if (insertPosition >= this.Items.Count)
                    this.Items.Add(item);
                else
                    this.Items.Insert(insertPosition, item);
            }
            else
                this.Items.Insert(insertPosition, item);

            return item;
        }