Пример #1
0
        public void MoveTabsTo(DockedTabControl target)
        {
            var children = TabStrip.Children.ToArray(); // copy because collection will be modified

            foreach (ControlBase child in children)
            {
                TabButton button = child as TabButton;
                if (button == null)
                {
                    continue;
                }
                target.AddPage(button);
            }
            Invalidate();
        }
Пример #2
0
        /// <summary>
        /// Adds a new page/tab.
        /// </summary>
        /// <param name="label">Tab label.</param>
        /// <param name="page">Page contents.</param>
        /// <returns>Newly created control.</returns>
        public TabPage AddPage(string label, ControlBase page = null)
        {
            TabButton button  = new TabButton(m_TabStrip);
            var       tabpage = new TabPage(this, button);

            tabpage.Name = label;
            button.SetText(label);
            button.Page      = tabpage;
            button.IsTabable = false;
            if (page != null)
            {
                tabpage.AddChild(page);
            }
            AddPage(button);
            return(tabpage);
        }
Пример #3
0
        /// <summary>
        /// Handler for tab removing.
        /// </summary>
        /// <param name="button"></param>
        internal virtual void OnLoseTab(TabButton button)
        {
            if (m_CurrentButton == button)
            {
                m_CurrentButton = null;
            }

            //TODO: Select a tab if any exist.

            if (TabRemoved != null)
            {
                TabRemoved.Invoke(this, EventArgs.Empty);
            }

            Invalidate();
        }
Пример #4
0
        /// <summary>
        /// Adds a new page/tab.
        /// </summary>
        /// <param name="label">Tab label.</param>
        /// <param name="page">Page contents.</param>
        /// <returns>Newly created control.</returns>
        public TabButton AddPage(string label, ControlBase page = null)
        {
            if (null == page)
            {
                page = new ControlBase(this);
            }
            else
            {
                page.Parent = this;
            }

            TabButton button = new TabButton(m_TabStrip);

            button.SetText(label);
            button.Page      = page;
            button.IsTabable = false;

            AddPage(button);
            return(button);
        }
Пример #5
0
        /// <summary>
        /// Handler for tab selection.
        /// </summary>
        /// <param name="control">Event source (TabButton).</param>
        internal virtual void OnTabPressed(ControlBase control, EventArgs args)
        {
            TabButton button = control as TabButton;

            if (null == button)
            {
                return;
            }

            ControlBase page = button.Page;

            if (null == page)
            {
                return;
            }

            if (m_CurrentButton == button)
            {
                return;
            }

            if (null != m_CurrentButton)
            {
                ControlBase page2 = m_CurrentButton.Page;
                if (page2 != null)
                {
                    page2.IsHidden = true;
                }
                m_CurrentButton.Redraw();
                m_CurrentButton = null;
            }

            m_CurrentButton = button;

            page.IsHidden = false;

            m_TabStrip.Invalidate();
            Invalidate();
        }
Пример #6
0
        public void RemoveTab(TabPage page)
        {
            var idx = -1;

            if (CurrentButton == page.TabButton)
            {
                idx = TabStrip.Children.IndexOf(page.TabButton);
                if (idx == TabStrip.Children.Count - 1)
                {
                    idx--;
                }
                m_CurrentButton = null;
            }
            TabStrip.RemoveChild(page.TabButton, true);
            RemoveChild(page, true);
            if (idx != -1)
            {
                GetPage(idx).FocusTab();
            }
            OnLoseTab(page.TabButton);
            Invalidate();
        }
Пример #7
0
 public void UpdateFromTab(TabButton button)
 {
     Text = button.Text;
     SizeToChildren();
 }
 public void UpdateFromTab(TabButton button)
 {
     Text = button.Text;
     SizeToContents();
 }
Пример #9
0
 private void UnsubscribeTabEvent(TabButton button)
 {
     button.Clicked -= OnTabPressed;
 }
        /// <summary>
        /// Lays out the control's interior according to alignment, padding, dock etc.
        /// </summary>
        /// <param name="skin">Skin to use.</param>
        protected override void Layout(Skin.SkinBase skin)
        {
            Point largestTab = new Point(5, 5);

            int num = 0;

            foreach (var child in Children)
            {
                TabButton button = child as TabButton;
                if (null == button)
                {
                    continue;
                }

                button.SizeToContents();

                Margin m        = new Margin();
                int    notFirst = num > 0 ? -1 : 0;

                if (Dock == Pos.Top)
                {
                    m.Left      = notFirst;
                    button.Dock = Pos.Left;
                }

                if (Dock == Pos.Left)
                {
                    m.Top       = notFirst;
                    button.Dock = Pos.Top;
                }

                if (Dock == Pos.Right)
                {
                    m.Top       = notFirst;
                    button.Dock = Pos.Top;
                }

                if (Dock == Pos.Bottom)
                {
                    m.Left      = notFirst;
                    button.Dock = Pos.Left;
                }

                largestTab.X = Math.Max(largestTab.X, button.Width);
                largestTab.Y = Math.Max(largestTab.Y, button.Height);

                button.Margin = m;
                num++;
            }

            if (Dock == Pos.Top || Dock == Pos.Bottom)
            {
                SetSize(Width, largestTab.Y);
            }

            if (Dock == Pos.Left || Dock == Pos.Right)
            {
                SetSize(largestTab.X, Height);
            }

            base.Layout(skin);
        }
Пример #11
0
 public void FocusTab()
 {
     TabButton.Press();
 }
Пример #12
0
 public TabPage(ControlBase parent, TabButton button) : base(parent)
 {
     m_ParentButton = button;
 }