/// <summary>
 /// Renders the background of the specified ribbon panel
 /// </summary>
 /// <param name="e">Event data and paint tools</param>
 public virtual void OnRenderRibbonPanelBackground(RibbonPanelRenderEventArgs e)
 {
 }
 /// <summary>
 /// Renders the text of the specified panel
 /// </summary>
 /// <param name="e">Event data and paint tools</param>
 public virtual void OnRenderRibbonPanelText(RibbonPanelRenderEventArgs e)
 {
 }
 public override void OnRenderRibbonPanelBackground(RibbonPanelRenderEventArgs e)
 {
     if (e.Panel.OverflowMode && !(e.Canvas is RibbonPanelPopup))
     {
         if (e.Panel.Pressed)
         {
             DrawPanelOverflowPressed(e);
         }
         else if (e.Panel.Selected)
         {
             DrawPannelOveflowSelected(e);
         }
         else
         {
             DrawPanelOverflowNormal(e);
         }
     }
     else
     {
         if (e.Panel.Selected)
         {
             DrawPanelSelected(e);
         }
         else
         {
             DrawPanelNormal(e);
         }
     }
 }
        public override void OnRenderRibbonPanelText(RibbonPanelRenderEventArgs e)
        {
            if (e.Panel.OverflowMode && !(e.Canvas is RibbonPanelPopup))
            {
                return;
            }

            Rectangle textArea =
                Rectangle.FromLTRB(
                e.Panel.Bounds.Left + 1,
                e.Panel.ContentBounds.Bottom,
                e.Panel.Bounds.Right - 1,
                e.Panel.Bounds.Bottom - 1);

            StringFormat sf = new StringFormat();
            sf.Alignment = StringAlignment.Center;
            sf.LineAlignment = StringAlignment.Center;

            using (Brush b = new SolidBrush(GetTextColor(e.Panel.Enabled)))
            {
                e.Graphics.DrawString(e.Panel.Text, e.Ribbon.Font, b, textArea, sf);
            }
        }
        /// <summary>
        /// Draws an overflown panel in selected state
        /// </summary>
        /// <param name="e"></param>
        public void DrawPannelOveflowSelected(RibbonPanelRenderEventArgs e)
        {
            Rectangle darkBorder = Rectangle.FromLTRB(
                e.Panel.Bounds.Left,
                e.Panel.Bounds.Top,
                e.Panel.Bounds.Right,
                e.Panel.Bounds.Bottom);

            Rectangle lightBorder = Rectangle.FromLTRB(
                e.Panel.Bounds.Left + 1,
                e.Panel.Bounds.Top + 1,
                e.Panel.Bounds.Right - 1,
                e.Panel.Bounds.Bottom - 1);

            GraphicsPath dark = RoundRectangle(darkBorder, 3);
            GraphicsPath light = RoundRectangle(lightBorder, 3);

            using (Pen p = new Pen(ColorTable.PanelLightBorder))
            {
                e.Graphics.DrawPath(p, light);
            }

            using (Pen p = new Pen(ColorTable.PanelDarkBorder))
            {
                e.Graphics.DrawPath(p, dark);
            }

            using (LinearGradientBrush b = new LinearGradientBrush(
                lightBorder, ColorTable.PanelOverflowBackgroundSelectedNorth, Color.Transparent, 90))
            {
                e.Graphics.FillPath(b, light);
            }

            DrawPanelOverflowImage(e);

            dark.Dispose();
            light.Dispose();
        }
        /// <summary>
        /// Draws a panel in selected state
        /// </summary>
        /// <param name="e"></param>
        public void DrawPanelSelected(RibbonPanelRenderEventArgs e)
        {
            Rectangle darkBorder = Rectangle.FromLTRB(
                e.Panel.Bounds.Left,
                e.Panel.Bounds.Top,
                e.Panel.Bounds.Right,
                e.Panel.Bounds.Bottom);

            Rectangle lightBorder = Rectangle.FromLTRB(
                e.Panel.Bounds.Left + 1,
                e.Panel.Bounds.Top + 1,
                e.Panel.Bounds.Right - 1,
                e.Panel.Bounds.Bottom - 1);

            Rectangle textArea =
                Rectangle.FromLTRB(
                e.Panel.Bounds.Left + 1,
                e.Panel.ContentBounds.Bottom,
                e.Panel.Bounds.Right - 1,
                e.Panel.Bounds.Bottom - 1);

            GraphicsPath dark = RoundRectangle(darkBorder, 3);
            GraphicsPath light = RoundRectangle(lightBorder, 3);
            GraphicsPath txt = RoundRectangle(textArea, 3, Corners.SouthEast | Corners.SouthWest);

            using (Pen p = new Pen(ColorTable.PanelLightBorder))
            {
                e.Graphics.DrawPath(p, light);
            }

            using (Pen p = new Pen(ColorTable.PanelDarkBorder))
            {
                e.Graphics.DrawPath(p, dark);
            }

            using (SolidBrush b = new SolidBrush(ColorTable.PanelBackgroundSelected))
            {
                e.Graphics.FillPath(b, light);
            }

            using (SolidBrush b = new SolidBrush(ColorTable.PanelTextBackground))
            {
                e.Graphics.FillPath(b, txt);
            }

            if (e.Panel.ButtonMoreVisible)
            {
                if (e.Panel.ButtonMorePressed)
                {
                    DrawButtonPressed(e.Graphics, e.Panel.ButtonMoreBounds, Corners.SouthEast);
                }
                else if(e.Panel.ButtonMoreSelected)
                {
                    DrawButtonSelected(e.Graphics, e.Panel.ButtonMoreBounds, Corners.SouthEast);
                }

                DrawButtonMoreGlyph(e.Graphics, e.Panel.ButtonMoreBounds, e.Panel.ButtonMoreEnabled && e.Panel.Enabled);
            }

            txt.Dispose();
            dark.Dispose();
            light.Dispose();
        }
        /// <summary>
        /// Draws an overflown panel in pressed state
        /// </summary>
        /// <param name="e"></param>
        public void DrawPanelOverflowPressed(RibbonPanelRenderEventArgs e)
        {
            Rectangle darkBorder = Rectangle.FromLTRB(
               e.Panel.Bounds.Left,
               e.Panel.Bounds.Top,
               e.Panel.Bounds.Right,
               e.Panel.Bounds.Bottom);

            Rectangle lightBorder = Rectangle.FromLTRB(
                e.Panel.Bounds.Left + 1,
                e.Panel.Bounds.Top + 1,
                e.Panel.Bounds.Right - 1,
                e.Panel.Bounds.Bottom - 1);

            Rectangle glossy = Rectangle.FromLTRB(
                e.Panel.Bounds.Left,
                e.Panel.Bounds.Top,
                e.Panel.Bounds.Right,
                e.Panel.Bounds.Top + 17);

            GraphicsPath dark = RoundRectangle(darkBorder, 3);
            GraphicsPath light = RoundRectangle(lightBorder, 3);

            using (LinearGradientBrush b = new LinearGradientBrush(lightBorder,
                ColorTable.PanelOverflowBackgroundPressed,
                ColorTable.PanelOverflowBackgroundSelectedSouth, 90))
            {
                b.WrapMode = WrapMode.TileFlipXY;
                e.Graphics.FillPath(b, dark);
            }

            using (GraphicsPath path = RoundRectangle(glossy, 3, Corners.NorthEast | Corners.NorthWest))
            {
                using (LinearGradientBrush b = new LinearGradientBrush(
                    glossy,
                    Color.FromArgb(150, Color.White),
                    Color.FromArgb(50, Color.White), 90
                    ))
                {
                    b.WrapMode = WrapMode.TileFlipXY;
                    e.Graphics.FillPath(b, path);
                }
            }

            using (Pen p = new Pen(Color.FromArgb(40, Color.White)))
            {
                e.Graphics.DrawPath(p, light);
            }

            using (Pen p = new Pen(ColorTable.PanelDarkBorder))
            {
                e.Graphics.DrawPath(p, dark);
            }

            DrawPanelOverflowImage(e);

            DrawPressedShadow(e.Graphics, glossy);

            dark.Dispose();
            light.Dispose();
        }
        /// <summary>
        /// Draws an overflown panel in normal state
        /// </summary>
        /// <param name="e"></param>
        public void DrawPanelOverflowNormal(RibbonPanelRenderEventArgs e)
        {
            Rectangle darkBorder = Rectangle.FromLTRB(
                e.Panel.Bounds.Left,
                e.Panel.Bounds.Top,
                e.Panel.Bounds.Right,
                e.Panel.Bounds.Bottom);

            Rectangle lightBorder = Rectangle.FromLTRB(
                e.Panel.Bounds.Left + 1,
                e.Panel.Bounds.Top + 1,
                e.Panel.Bounds.Right - 1,
                e.Panel.Bounds.Bottom - 1);

            GraphicsPath dark = RoundRectangle(darkBorder, 3);
            GraphicsPath light = RoundRectangle(lightBorder, 3);

            using (Pen p = new Pen(ColorTable.PanelLightBorder))
            {
                e.Graphics.DrawPath(p, light);
            }

            using (Pen p = new Pen(ColorTable.PanelDarkBorder))
            {
                e.Graphics.DrawPath(p, dark);
            }

            DrawPanelOverflowImage(e);

            dark.Dispose();
            light.Dispose();
        }
        /// <summary>
        /// Draws the image of the panel when collapsed
        /// </summary>
        /// <param name="e"></param>
        public void DrawPanelOverflowImage(RibbonPanelRenderEventArgs e)
        {
            int margin =3;
            Size imgSquareSize = new Size(32, 32);
            Rectangle imgSquareR = new Rectangle(new Point(
                e.Panel.Bounds.Left + (e.Panel.Bounds.Width - imgSquareSize.Width) / 2,
                e.Panel.Bounds.Top+ 5), imgSquareSize);

            Rectangle imgSquareBottomR = Rectangle.FromLTRB(
                imgSquareR.Left, imgSquareR.Bottom - 10, imgSquareR.Right, imgSquareR.Bottom);

            Rectangle textR = Rectangle.FromLTRB(
                e.Panel.Bounds.Left + margin,
                imgSquareR.Bottom + margin,
                e.Panel.Bounds.Right - margin,
                e.Panel.Bounds.Bottom - margin);

            GraphicsPath imgSq = RoundRectangle(imgSquareR, 5);
            GraphicsPath imgSqB = RoundRectangle(imgSquareBottomR, 5, Corners.South);

            using (LinearGradientBrush b = new LinearGradientBrush(
                imgSquareR, ColorTable.TabContentNorth, ColorTable.TabContentSouth, 90
                ))
            {
                e.Graphics.FillPath(b, imgSq);
            }

            using (SolidBrush b = new SolidBrush(ColorTable.PanelTextBackground))
            {
                e.Graphics.FillPath(b, imgSqB);
            }

            using (Pen p = new Pen(ColorTable.PanelDarkBorder))
            {
                e.Graphics.DrawPath(p, imgSq);
            }

            if (e.Panel.Image != null)
            {
                e.Graphics.DrawImage(e.Panel.Image,
                    new Point(
                        imgSquareR.Left + (imgSquareR.Width - e.Panel.Image.Width) / 2,
                        imgSquareR.Top + ((imgSquareR.Height - imgSquareBottomR.Height) - e.Panel.Image.Height) / 2));

            }

            using (SolidBrush b = new SolidBrush(GetTextColor(e.Panel.Enabled)))
            {
                StringFormat sf = new StringFormat();
                sf.Alignment = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Near;
                sf.Trimming = StringTrimming.Character;

                e.Graphics.DrawString(e.Panel.Text, e.Ribbon.Font, b, textR, sf);
            }

            Rectangle bounds = LargeButtonDropDownArrowBounds(e.Graphics, e.Panel.Owner.Font, e.Panel.Text, textR);

            if (bounds.Right < e.Panel.Bounds.Right)
            {

                Rectangle boundsLight = bounds; boundsLight.Offset(0, 1);

                Color lt = ColorTable.ArrowLight;
                Color dk = ColorTable.Arrow;

                DrawArrow(e.Graphics, boundsLight, lt, Direction.Down);
                DrawArrow(e.Graphics, bounds, dk, Direction.Down);

            }
            imgSq.Dispose();
            imgSqB.Dispose();
        }