コード例 #1
0
        /// <summary>
        /// Returns the bounding rectangle for a specified tab in this tab control.
        /// </summary>
        /// <param name="page">The Tab Page to retrieve the bounds for.</param>
        /// <returns>A <see cref="Rectangle"/> that represents the bounds of the specified tab.</returns>
        public virtual Rectangle GetTabRect(BpTabPage page)
        {
            TabPosition position = positions[page];
            int         row      = position.Row;

            if (selectedRow > row)
            {
                row++;
            }
            else if (selectedRow == row)
            {
                row = 0;
            }
            Rectangle result = Rectangle.Empty;

            result.X      = tabsRectangle.Left + position.Offset + tabExpand.Left;
            result.Width  = position.Size.Width;
            result.Y      = tabsRectangle.Bottom - (row * tabHeight) - tabHeight;
            result.Height = tabHeight;
            if (page == selectedTab)
            {
                result.Y      -= tabExpand.Top;
                result.Height += tabExpand.Vertical;
                result.X      -= tabExpand.Left;
                result.Width  += tabExpand.Horizontal;
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Determine whether to display a close icon on the given tab.
        /// </summary>
        /// <param name="page">The tab</param>
        /// <returns>True if a close button should be displayed.</returns>
        public bool IncludesCloseButton(BpTabPage page)
        {
            if (closeStyle == TabCloseStyle.All)
            {
                return(true);
            }

            if (closeStyle == TabCloseStyle.None)
            {
                return(false);
            }

            if (page == selectedTab)
            {
                return(closeStyle == TabCloseStyle.Selected || closeStyle == TabCloseStyle.SelectedAndHover);
            }

            if (page == clickClose)
            {
                return(true);
            }

            if (page == hoverTab)
            {
                if (clickClose != null)
                {
                    return(false);
                }
                return(closeStyle == TabCloseStyle.Hover || closeStyle == TabCloseStyle.SelectedAndHover);
            }

            return(false);
        }
コード例 #3
0
 /// <summary>
 /// Overridden. Inherited from <see cref="Control"/>.
 /// </summary>
 /// <param name="cea">
 /// See <see cref="Control.OnControlRemoved(ControlEventArgs)"/>.
 /// </param>
 protected override void OnControlRemoved(ControlEventArgs cea)
 {
     base.OnControlRemoved(cea);
     if (Controls.Count > 0)
     {
         if (cea.Control == selectedTab)
         {
             selectedIndex       = Math.Min(selectedIndex, Controls.Count - 1);
             selectedTab         = (BpTabPage)Controls[selectedIndex];
             selectedTab.Visible = true;
         }
         else
         {
             selectedIndex = Controls.IndexOf(selectedTab);
             selectedRow   = positions[selectedTab].Row;
         }
     }
     else
     {
         selectedIndex = -1;
         selectedTab   = null;
         selectedRow   = -1;
     }
     if (cea.Control == hoverTab)
     {
         hoverTab   = null;
         hoverClose = false;
     }
     if (cea.Control == clickClose)
     {
         clickClose = null;
     }
     CalculateRectangles();
     ((BpTabPage)cea.Control).TabChanged -= tabEventHandler;
 }
コード例 #4
0
        protected virtual void OnTabMouseDown(TabMouseEventArgs e)
        {
            if (TabMouseDown != null)
            {
                TabMouseDown(this, e);
            }

            if (IncludesCloseButton(e.TabPage))
            {
                Rectangle closerect = GetTabCloseRect(e.TabPage, e.TabBounds);
                if (closerect.Contains(e.Location))
                {
                    clickClose = e.TabPage;
                    Invalidate(closerect);
                    Update();
                    return;
                }
            }
            if (e.Button == MouseButtons.Left)
            {
                if (!e.TabPage.Disabled)
                {
                    SelectedTab = e.TabPage;
                }
            }

            Rectangle bounds = GetTabContentRect(e.TabPage, e.TabBounds);

            e.TabPage.CallTabMouseDown(new TabMouseEventArgs(e.Button, e.Clicks, e.X, e.Y, e.Delta, e.TabPage, Bounds));
        }
コード例 #5
0
        protected void PaintTab(BpTabPage page, Graphics g)
        {
            Rectangle          bounds  = GetTabRect(page);
            VisualStyleElement element = GetElement(page);

            if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element))
            {
                VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                renderer.DrawBackground(g, bounds);
                bounds = renderer.GetBackgroundContentRectangle(g, bounds);
            }
            else
            {
                ControlPaint.DrawBorder3D(g, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Middle);
            }

            if (IncludesCloseButton(page))
            {
                Rectangle closerect = GetTabCloseRect(page, bounds);
                element = VisualStyleElement.ToolTip.Close.Normal;
                Border3DStyle borderstyle = Border3DStyle.Flat;
                if (hoverClose)
                {
                    if (clickClose == page)
                    {
                        element     = VisualStyleElement.ToolTip.Close.Pressed;
                        borderstyle = Border3DStyle.Sunken;
                    }
                    else if (clickClose == null)
                    {
                        element     = VisualStyleElement.ToolTip.Close.Hot;
                        borderstyle = Border3DStyle.Raised;
                    }
                }
                if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element))
                {
                    VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                    renderer.DrawBackground(g, closerect);
                }
                else
                {
                    if (borderstyle != Border3DStyle.Flat)
                    {
                        ControlPaint.DrawBorder3D(g, closerect, borderstyle);
                    }
                    Font  closefont = new Font("Marlett", SystemFonts.MenuFont.Size);
                    Point pos       = closerect.Location;
                    pos.X += SystemInformation.Border3DSize.Width;
                    pos.Y += SystemInformation.Border3DSize.Height;
                    TextRenderer.DrawText(g, "r", closefont, pos, Color.Black);
                }
            }

            bounds = GetTabContentRect(page, bounds);
            TabPaintEventArgs ea = new TabPaintEventArgs(g, bounds, page);

            OnTabPaint(ea);
            page.CallTabPaint(ea);
        }
コード例 #6
0
 public virtual Rectangle GetTabCloseRect(BpTabPage page)
 {
     if (!IncludesCloseButton(page))
     {
         return(Rectangle.Empty);
     }
     return(GetTabCloseRect(page, GetTabRect(page)));
 }
コード例 #7
0
        /// <summary>
        /// Returns the bounding rectangle for a specified tab in this tab control.
        /// </summary>
        /// <param name="index">The 0-based index of the tab you want.</param>
        /// <returns>A <see cref="Rectangle"/> that represents the bounds of the specified tab.</returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// The index is less than zero.<br />-or-<br />The index is greater than or equal to <see cref="Control.ControlCollection.Count" />.
        /// </exception>
        public virtual Rectangle GetTabRect(int index)
        {
            if ((index < 0) || (index > Controls.Count))
            {
                throw new ArgumentNullException("index", "Index outside of allowed range.");
            }
            BpTabPage page = (BpTabPage)Controls[index];

            return(GetTabRect(page));
        }
コード例 #8
0
        /// <summary>
        /// Gives the correct <see cref="VisualStyleElement"/> to use for
        /// a give tab.
        /// </summary>
        /// <param name="page">The tab to return the element for.</param>
        /// <returns>The element to use when rendering the tab.</returns>
        internal VisualStyleElement GetElement(BpTabPage page)
        {
            string className = "TAB";
            int    part;
            int    state;

            if (page == selectedTab)
            {
                state = 3;
            }
            else if (page.Disabled)
            {
                state = 4;
            }
            else if (page == hoverTab)
            {
                state = 2;
            }
            else
            {
                state = 1;
            }

            TabPosition position = positions[page];
            int         toprow   = rows - 1;

            if ((rows > 1) && (toprow == selectedRow))
            {
                toprow--;
            }

            if (rowCounts[position.Row] == 1)
            {
                part = 1;
            }
            else if (position.Pos == rowCounts[position.Row] - 1)
            {
                part = 2;
            }
            else if (position.Pos == 0)
            {
                part = 3;
            }
            else
            {
                part = 4;
            }

            if (position.Row == toprow)
            {
                part += 4;
            }

            return(VisualStyleElement.CreateElement(className, part, state));
        }
コード例 #9
0
 /// <summary>
 /// Overridden. Inherited from <see cref="Control"/>.
 /// </summary>
 /// <param name="cea">
 /// See <see cref="Control.OnControlAdded(ControlEventArgs)"/>.
 /// </param>
 protected override void OnControlAdded(ControlEventArgs cea)
 {
     base.OnControlAdded(cea);
     cea.Control.Visible = false;
     if (selectedIndex == -1)
     {
         selectedIndex       = 0;
         selectedTab         = (BpTabPage)cea.Control;
         selectedTab.Visible = true;
     }
     CalculateRectangles();
     ((BpTabPage)cea.Control).TabChanged += tabEventHandler;
 }
コード例 #10
0
            /// <summary>
            /// Creates a new instance of the
            /// <see cref="BpTabPage.ControlCollection"/> class with
            /// the specified <i>owner</i>.
            /// </summary>
            /// <param name="owner">
            /// The <see cref="BpTabPage"/> that owns this collection.
            /// </param>
            /// <exception cref="ArgumentNullException">
            /// Thrown if <i>owner</i> is <b>null</b>.
            /// </exception>
            /// <exception cref="ArgumentException">
            /// Thrown if <i>owner</i> is not a <see cref="BpTabPage"/>.
            /// </exception>
            public ControlCollection(Control owner) : base(owner)
            {
                if (owner == null)
                {
                    throw new ArgumentNullException("owner", "Tried to create a BpTabPage.ControlCollection with a null owner.");
                }
                BpTabPage c = owner as BpTabPage;

                if (c == null)
                {
                    throw new ArgumentException("Tried to create a BpTabPage.ControlCollection with a non-BpTabPage owner.", "owner");
                }
            }
コード例 #11
0
        protected virtual void OnTabMouseEnter(TabEventArgs e)
        {
            if (TabMouseEnter != null)
            {
                TabMouseEnter(this, e);
            }

            hoverTab = e.TabPage;
            Invalidate(GetTabRect(e.TabPage));

            e.TabPage.CallTabMouseEnter(e);
            Update();
        }
コード例 #12
0
            /// <summary>
            /// Overridden. Adds a <see cref="Control"/> to the
            /// <see cref="BpTabControl"/>.
            /// </summary>
            /// <param name="value">
            /// The <see cref="Control"/> to add, which must be a
            /// <see cref="BpTabPage"/>.
            /// </param>
            /// <exception cref="ArgumentNullException">
            /// Thrown if <i>value</i> is <b>null</b>.
            /// </exception>
            /// <exception cref="ArgumentException">
            /// Thrown if <i>value</i> is not a <see cref="BpTabPage"/>.
            /// </exception>
            public override void Add(Control value)
            {
                if (value == null)
                {
                    throw new ArgumentNullException("value", "Tried to add a null value to the BpTabControl.ControlCollection.");
                }
                BpTabPage p = value as BpTabPage;

                if (p == null)
                {
                    throw new ArgumentException("Tried to add a non-BpTabPage control to the BpTabControl.ControlCollection.", "value");
                }
                p.SendToBack();
                base.Add(p);
            }
コード例 #13
0
 /// <summary>
 /// Gives the quick estimation of the <see cref="VisualStyleElement"/>
 /// to use for a give tab.
 /// </summary>
 /// <param name="page">The tab to return the element for.</param>
 /// <returns>The element to use when rendering the tab.</returns>
 internal VisualStyleElement GetGuessedElement(BpTabPage page)
 {
     if (page == selectedTab)
     {
         return(VisualStyleElement.Tab.TabItem.Pressed);
     }
     else if (page.Disabled)
     {
         return(VisualStyleElement.Tab.TabItem.Disabled);
     }
     else if (page == hoverTab)
     {
         return(VisualStyleElement.Tab.TabItem.Hot);
     }
     else
     {
         return(VisualStyleElement.Tab.TabItem.Normal);
     }
 }
コード例 #14
0
        public virtual Rectangle GetTabCloseRect(BpTabPage page, Rectangle tab)
        {
            if (!IncludesCloseButton(page))
            {
                return(Rectangle.Empty);
            }

            Graphics            g = CreateGraphics();
            VisualStyleRenderer renderer;
            Rectangle           bounds  = new Rectangle(tab.X, tab.Y, tab.Width, tab.Height);
            VisualStyleElement  element = GetElement(page);

            if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element))
            {
                renderer = new VisualStyleRenderer(element);
                bounds   = renderer.GetBackgroundContentRectangle(g, bounds);
            }
            bounds.X      += SystemInformation.Border3DSize.Width;
            bounds.Y      += SystemInformation.Border3DSize.Height;
            bounds.Width  -= SystemInformation.Border3DSize.Width * 2;
            bounds.Height -= SystemInformation.Border3DSize.Height * 2;

            Size closesize;

            element = VisualStyleElement.ToolTip.Close.Normal;
            if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element))
            {
                renderer  = new VisualStyleRenderer(element);
                closesize = renderer.GetPartSize(g, ThemeSizeType.Draw);
            }
            else
            {
                Font closefont = new Font("Marlett", SystemFonts.MenuFont.Size);
                closesize         = TextRenderer.MeasureText("r", closefont);
                closesize.Height += SystemInformation.Border3DSize.Height * 2;
                closesize.Width  += SystemInformation.Border3DSize.Width * 2;
            }
            bounds.X      = bounds.Right - closesize.Width;
            bounds.Width  = closesize.Width;
            bounds.Y     += (bounds.Height - closesize.Height) / 2;
            bounds.Height = closesize.Height;
            return(bounds);
        }
コード例 #15
0
 /// <summary>
 /// Inherited from <see cref="Control"/>.
 /// </summary>
 /// <param name="e">
 /// See <see cref="Control.OnMouseUp(EventArgs)"/>.
 /// </param>
 protected override void OnMouseUp(MouseEventArgs e)
 {
     base.OnMouseUp(e);
     if (tabsRectangle.Contains(e.Location))
     {
         foreach (BpTabPage page in Controls)
         {
             Rectangle bounds = GetTabRect(page);
             if (bounds.Contains(e.Location))
             {
                 this.OnTabMouseUp(new TabMouseEventArgs(e, page, bounds));
                 break;
             }
         }
     }
     if (clickClose != null)
     {
         Invalidate(GetTabCloseRect(clickClose));
         clickClose = null;
         Update();
     }
 }
コード例 #16
0
        protected virtual void OnTabMouseLeave(TabEventArgs e)
        {
            if (TabMouseLeave != null)
            {
                TabMouseLeave(this, e);
            }

            if (hoverTab == e.TabPage)
            {
                hoverTab   = null;
                hoverClose = false;
            }
            else
            {
                Debug.WriteLine("Mouse left non-hover tab.");
            }

            Invalidate(GetTabRect(e.TabPage));

            e.TabPage.CallTabMouseLeave(e);
            Update();
        }
コード例 #17
0
 public TabPaintEventArgs(Graphics g, Rectangle clip, BpTabPage page)
     : base(g, clip)
 {
     this.page = page;
 }
コード例 #18
0
 public TabMouseEventArgs(MouseEventArgs e, BpTabPage page, Rectangle bounds)
     : base(e.Button, e.Clicks, e.X, e.Y, e.Delta)
 {
     this.page   = page;
     this.bounds = bounds;
 }
コード例 #19
0
 public TabMouseEventArgs(MouseButtons button, int clicks, int x, int y, int delta, BpTabPage page, Rectangle bounds)
     : base(button, clicks, x, y, delta)
 {
     this.page   = page;
     this.bounds = bounds;
 }
コード例 #20
0
 public TabEventArgs(BpTabPage page)
     : base()
 {
     this.page = page;
 }
コード例 #21
0
 public TabClosingEventArgs(BpTabPage page)
     : base(page)
 {
 }
コード例 #22
0
 /// <summary>
 /// Creates an instance of the <see cref="TabChangingEventArgs"/>
 /// class with the specified indices.
 /// </summary>
 /// <param name="currentIndex">The current selected index of the <see cref="BpTabControl"/>.</param>
 /// <param name="newIndex">The value to which the selected index changes.</param>
 public TabChangingEventArgs(BpTabPage current, BpTabPage newtab)
 {
     this.cIndex = current;
     this.nIndex = newtab;
 }
コード例 #23
0
 public virtual Rectangle GetTabContentRect(BpTabPage page)
 {
     return(GetTabContentRect(page, GetTabRect(page)));
 }