public override void OnRenderRibbonItemImage(RibbonItemBoundsEventArgs e)
        {
            Image img = e.Item.ShowFlashImage ? e.Item.FlashImage : e.Item.Image;

            if (e.Item is RibbonButton)
            {
                if (!(e.Item.SizeMode == RibbonElementSizeMode.Large || e.Item.SizeMode == RibbonElementSizeMode.Overflow))
                {
                    img = e.Item.ShowFlashImage ? (e.Item as RibbonButton).FlashSmallImage : (e.Item as RibbonButton).SmallImage;
                }

                if (e.Item.SizeMode == RibbonElementSizeMode.DropDown && e.Item.Checked)
                {
                    using (Pen p = new Pen(ColorTable.DropDownCheckedButtonGlyphBorder))
                    {
                        using (SolidBrush brus = new SolidBrush(ColorTable.DropDownCheckedButtonGlyphBg))
                        {
                           Rectangle outerR = Rectangle.FromLTRB(e.Bounds.Left - 2, e.Bounds.Top - 2, e.Bounds.Right + 1, e.Bounds.Bottom + 1);

                           using (GraphicsPath r = RoundRectangle(outerR, 3, Corners.All))
                            {
                                SmoothingMode smb = e.Graphics.SmoothingMode;
                                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                                e.Graphics.DrawPath(p, r);
                                e.Graphics.FillPath(brus, r);
                                e.Graphics.SmoothingMode = smb;
                            }

                            //Draw fake check
                            if (img != null)
                            {
                                Rectangle glyphR = new Rectangle(e.Bounds.Left + 1, e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
                                ControlPaint.DrawMenuGlyph(e.Graphics, glyphR, MenuGlyph.Checkmark, p.Color, Color.Transparent);
                            }
                        }

                    }
                }
            }

            if (img != null)
            {

                if (!e.Item.Enabled)
                    img = CreateDisabledImage(img);

                e.Graphics.DrawImage(img, e.Bounds);
            }

        }
Example #2
0
 /// <summary>
 /// Renders the image of the item specified on the event
 /// </summary>
 public virtual void OnRenderRibbonItemImage(RibbonItemBoundsEventArgs e)
 {
 }
        public override void OnRenderRibbonItemImage(RibbonItemBoundsEventArgs e)
        {
            Image img = e.Item.ShowFlashImage ? e.Item.FlashImage : e.Item.Image;

            if (e.Item is RibbonButton)
            {
                if (!(e.Item.SizeMode == RibbonElementSizeMode.Large || e.Item.SizeMode == RibbonElementSizeMode.Overflow))
                {
                    img = e.Item.ShowFlashImage ? (e.Item as RibbonButton).SmallImage : (e.Item as RibbonButton).SmallImage;
                }
            }

            if (img != null)
            {

                if (!e.Item.Enabled)
                    img = CreateDisabledImage(img);

                e.Graphics.DrawImage(img, e.Bounds);
            }
        }
 /// <summary>
 /// Renders the image of the item specified on the event
 /// </summary>
 public virtual void OnRenderRibbonItemImage(RibbonItemBoundsEventArgs e)
 {
 }
        public override void OnRenderRibbonItemText(RibbonItemBoundsEventArgs e)
        {
            if (e.Item is RibbonButton)
            {
                #region Button
                RibbonButton b = e.Item as RibbonButton;
                StringFormat sf = new StringFormat();

                sf.LineAlignment = StringAlignment.Center;
                sf.Alignment = StringAlignment.Near;

                if (e.Item.SizeMode == RibbonElementSizeMode.Large)
                {
                    sf.Alignment = StringAlignment.Center;

                    if (!string.IsNullOrEmpty(e.Item.Text) && !e.Item.Text.Contains(" "))
                    {
                        sf.LineAlignment = StringAlignment.Near;
                    }
                }

                using (SolidBrush brush = new SolidBrush(GetTextColor(e.Item.Enabled)))
                {
                    e.Graphics.DrawString(e.Item.Text, e.Ribbon.Font, brush, e.Bounds, sf);
                }

                if (b.Style == RibbonButtonStyle.DropDown && b.SizeMode == RibbonElementSizeMode.Large)
                {
                    DrawButtonDropDownArrow(e.Graphics, b, e.Bounds);
                }
                #endregion
            }
            else if (e.Item is RibbonSeparator)
            {
                #region Separator
                DrawSeparatorText(e, e.Item as RibbonSeparator);
                #endregion
            }
            else if (e.Item is RibbonTextBox)
            {
                #region Textbox
                DrawTextBoxText(e.Graphics, e);
                #endregion
            }
            else
            {
                #region Generic
                e.Graphics.DrawString(e.Item.Text, e.Ribbon.Font, SystemBrushes.ControlText, e.Bounds);
                #endregion
            }
        }
        /// <summary>
        /// Draws the text of a RibbonTextbox
        /// </summary>
        /// <param name="g"></param>
        /// <param name="e"></param>
        public void DrawTextBoxText(Graphics g, RibbonItemBoundsEventArgs e)
        {
            RibbonTextBox t = e.Item as RibbonTextBox;

            StringFormat f = new StringFormat();

            f.Alignment = StringAlignment.Near;
            f.LineAlignment = StringAlignment.Center;
            f.Trimming = StringTrimming.None;
            f.FormatFlags |= StringFormatFlags.NoWrap;

            e.Graphics.DrawString(t.TextBoxText, e.Ribbon.Font,
                t.Enabled ? SystemBrushes.ControlText : SystemBrushes.GrayText, t.TextBoxTextBounds, f);

            if (t.LabelVisible)
            {
                using (Brush b = new SolidBrush(GetTextColor(e.Item.Enabled)))
                {
                    e.Graphics.DrawString(t.Text, e.Ribbon.Font, b, t.LabelBounds, f);
                }
            }
        }
 public void DrawSeparatorText(RibbonItemBoundsEventArgs e, RibbonSeparator sep)
 {
     using (Brush b = new SolidBrush(GetTextColor(sep.Enabled)))
     {
         e.Graphics.DrawString(sep.Text, new Font(sep.Owner.Font, FontStyle.Bold), b, e.Bounds);
     }
 }