Exemple #1
0
 /// <summary>
 /// Renders the text of the context specified on the event
 /// </summary>
 /// <param name="e">Event data and paint tools</param>
 public virtual void OnRenderRibbonContextText(RibbonContextRenderEventArgs e)
 {
 }
        public override void OnRenderRibbonContextText(RibbonContextRenderEventArgs e)
        {
            StringFormat sf = StringFormatFactory.CenterNoWrapTrimEllipsis();
            sf.LineAlignment = StringAlignment.Near;

            Rectangle r = Rectangle.FromLTRB(e.Context.Bounds.Left + e.Ribbon.TabTextMargin.Left,
                e.Context.Bounds.Top + e.Ribbon.TabTextMargin.Top + 3,
                e.Context.Bounds.Right - e.Ribbon.TabTextMargin.Right,
                e.Context.Bounds.Bottom - e.Ribbon.TabTextMargin.Bottom);
            Rectangle rShadow = r;
            rShadow.Offset(0, 1);

            var tabText = e.Context.Text;

            if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2007 || e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2010 || e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2013)
            {
                // Text Shadow
                using (Brush b = new SolidBrush(GetTextColor(true, DarkenColor(e.Context.GlowColor, 0.5F))))
                {
                    if (e.Ribbon.ActualBorderMode == RibbonWindowMode.NonClientAreaGlass)
                    {
                        GraphicsPath p = new GraphicsPath();

                        float emSize = e.Graphics.DpiY * e.Ribbon.RibbonTabFont.Size / 72;
                        p.AddString(tabText, e.Ribbon.RibbonTabFont.FontFamily, (int)FontStyle.Bold, emSize, rShadow, sf);

                        SmoothingMode sbuff = e.Graphics.SmoothingMode;
                        e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                        e.Graphics.FillPath(b, p);
                        e.Graphics.SmoothingMode = sbuff;
                    }
                    else
                    {
                        e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                        Font boldfont = new Font(e.Ribbon.RibbonTabFont, FontStyle.Bold);
                        e.Graphics.DrawString(tabText, boldfont, b, rShadow, sf);
                    }
                }

                // Text
                using (Brush b = new SolidBrush(GetTextColor(true, Color.White)))
                {
                    if (e.Ribbon.ActualBorderMode == RibbonWindowMode.NonClientAreaGlass)
                    {
                        GraphicsPath p = new GraphicsPath();

                        float emSize = e.Graphics.DpiY * e.Ribbon.RibbonTabFont.Size / 72;
                        p.AddString(tabText, e.Ribbon.RibbonTabFont.FontFamily, (int)FontStyle.Bold, emSize, r, sf);

                        SmoothingMode sbuff = e.Graphics.SmoothingMode;
                        e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                        e.Graphics.FillPath(b, p);
                        e.Graphics.SmoothingMode = sbuff;
                    }
                    else
                    {
                        e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                        Font boldfont = new Font(e.Ribbon.RibbonTabFont, FontStyle.Bold);
                        e.Graphics.DrawString(tabText, boldfont, b, r, sf);
                    }
                }
            }
        }
 public override void OnRenderRibbonContext(RibbonContextRenderEventArgs e)
 {
     DrawContextNormal(e);
 }
        private void DrawContextNormal(RibbonContextRenderEventArgs e)
        {
            RectangleF lastClip = e.Graphics.ClipBounds;

            Rectangle clip = Rectangle.FromLTRB(
                      e.Context.Bounds.Left,
                      e.Context.Bounds.Top,
                      e.Context.Bounds.Right,
                      e.Context.Bounds.Bottom);

            Rectangle r = Rectangle.FromLTRB(
                 e.Context.Bounds.Left,
                 e.Context.Bounds.Top,
                 e.Context.Bounds.Right,
                 e.Context.Bounds.Bottom);

            Rectangle rH = Rectangle.FromLTRB(
                 e.Context.HeaderBounds.Left,
                 e.Context.HeaderBounds.Top,
                 e.Context.HeaderBounds.Right,
                 e.Context.HeaderBounds.Bottom);

            Rectangle rBar = Rectangle.FromLTRB(
                 e.Context.Bounds.Left,
                 e.Context.Bounds.Top,
                 e.Context.Bounds.Right,
                 e.Context.Bounds.Top + 5);

            e.Graphics.SetClip(clip);

            #region Office_2007

            if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2007)
            {
                Color north = Color.FromArgb(200, DarkenColor(e.Context.GlowColor, 0.3F));
                Color centre = Color.FromArgb(120, DarkenColor(e.Context.GlowColor, 0.2F));
                Color south = Color.FromArgb(40, DarkenColor(e.Context.GlowColor, 0.0F));

                //Main context portion
                using (LinearGradientBrush b = new LinearGradientBrush(
                        rH, north, south, 90))
                {
                    ColorBlend cb = new ColorBlend(3);
                    cb.Colors = new Color[] { north, centre, south };
                    cb.Positions = new float[] { 0f, .3f, 1f };
                    b.InterpolationColors = cb;

                    SmoothingMode sbuff = e.Graphics.SmoothingMode;
                    e.Graphics.SmoothingMode = SmoothingMode.None;
                    e.Graphics.FillRectangle(b, rH);
                    //e.Graphics.DrawRectangle(new Pen(b, 1), rH);
                    e.Graphics.SmoothingMode = sbuff;
                }

                //Thick top bar
                using (Brush b = new SolidBrush(e.Context.GlowColor))
                {
                    SmoothingMode sbuff = e.Graphics.SmoothingMode;
                    e.Graphics.SmoothingMode = SmoothingMode.None;
                    e.Graphics.FillRectangle(b, rBar);
                    //e.Graphics.DrawRectangle(new Pen(b, 1), rBar);
                    e.Graphics.SmoothingMode = sbuff;
                }
            }

            #endregion

            #region Office_2010

            if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2010)
            {

                Color north = Color.FromArgb(200, DarkenColor(e.Context.GlowColor, 0.3F));
                Color centre = Color.FromArgb(120, DarkenColor(e.Context.GlowColor, 0.2F));
                Color south = Color.FromArgb(40, DarkenColor(e.Context.GlowColor, 0.0F));

                //Main context portion
                using (LinearGradientBrush b = new LinearGradientBrush(
                        rH, north, south, 90))
                {
                    ColorBlend cb = new ColorBlend(3);
                    cb.Colors = new Color[] { north, centre, south };
                    cb.Positions = new float[] { 0f, .3f, 1f };
                    b.InterpolationColors = cb;

                    SmoothingMode sbuff = e.Graphics.SmoothingMode;
                    e.Graphics.SmoothingMode = SmoothingMode.None;
                    e.Graphics.FillRectangle(b, rH);
                    //e.Graphics.DrawRectangle(new Pen(b, 1), rH);
                    e.Graphics.SmoothingMode = sbuff;
                }
                
                //Thick top bar
                using (Brush b = new SolidBrush(e.Context.GlowColor))
                {
                    SmoothingMode sbuff = e.Graphics.SmoothingMode;
                    e.Graphics.SmoothingMode = SmoothingMode.None;
                    e.Graphics.FillRectangle(b, rBar);
                    //e.Graphics.DrawRectangle(new Pen(b, 1), rBar);
                    e.Graphics.SmoothingMode = sbuff;
                }

            }

            #endregion

            #region Office_2013

            if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2013)
            {
                Color north = Color.FromArgb(200, DarkenColor(e.Context.GlowColor, 0.3F));
                Color centre = Color.FromArgb(120, DarkenColor(e.Context.GlowColor, 0.2F));
                Color south = Color.FromArgb(40, DarkenColor(e.Context.GlowColor, 0.0F));

                //Main context portion
                using (LinearGradientBrush b = new LinearGradientBrush(
                        rH, north, south, 90))
                {
                    ColorBlend cb = new ColorBlend(3);
                    cb.Colors = new Color[] { north, centre, south };
                    cb.Positions = new float[] { 0f, .3f, 1f };
                    b.InterpolationColors = cb;

                    SmoothingMode sbuff = e.Graphics.SmoothingMode;
                    e.Graphics.SmoothingMode = SmoothingMode.None;
                    e.Graphics.FillRectangle(b, rH);
                    //e.Graphics.DrawRectangle(new Pen(b, 1), rH);
                    e.Graphics.SmoothingMode = sbuff;
                }

                //Thick top bar
                using (Brush b = new SolidBrush(e.Context.GlowColor))
                {
                    SmoothingMode sbuff = e.Graphics.SmoothingMode;
                    e.Graphics.SmoothingMode = SmoothingMode.None;
                    e.Graphics.FillRectangle(b, rBar);
                    //e.Graphics.DrawRectangle(new Pen(b, 1), rBar);
                    e.Graphics.SmoothingMode = sbuff;
                }
            }

            #endregion

            e.Graphics.SetClip(lastClip);
        }
      /// <summary>
      /// Renders the text of the context specified on the event
      /// </summary>
      /// <param name="e">Event data and paint tools</param>
      public virtual void OnRenderRibbonContextText(RibbonContextRenderEventArgs e)
      {

      }