Exemple #1
0
 /// <summary>
 /// Renders the border of the item, after the text and image of the item
 /// </summary>
 /// <param name="e"></param>
 public virtual void OnRenderRibbonItemBorder(RibbonItemRenderEventArgs e)
 {
 }
        public override void OnRenderRibbonItem(RibbonItemRenderEventArgs e)
        {
            if (e.Item is RibbonButton)
            {
                #region Button
                RibbonButton b = e.Item as RibbonButton;

                if (b.Enabled)
                {
                    if (b.Style == RibbonButtonStyle.Normal)
                    {
                        if (b.SizeMode == RibbonElementSizeMode.DropDown)
                        {
                            // Buttons on a dropdown only have Selected background.
                            // On Pressed, the menu closes. When Checked, the image not the button is highlighted.
                            if (b.Selected)
                            {
                                DrawButtonSelected(e.Graphics, b, e.Ribbon);
                            }
                            else
                            {
                                //No background
                            }
                        }
                        else if (b.Pressed)
                        {
                            DrawButtonPressed(e.Graphics, b, e.Ribbon);
                        }
                        else if (b.Selected && b.Checked)
                        {
                            DrawButtonCheckedSelected(e.Graphics, b, e.Ribbon);
                        }
                        else if (b.Selected && !b.Checked)
                        {
                            DrawButtonSelected(e.Graphics, b, e.Ribbon);
                        }
                        else if (b.Checked)
                        {
                            DrawButtonChecked(e.Graphics, b, e.Ribbon);
                        }
                        else if (b is RibbonOrbOptionButton)
                        {
                            DrawOrbOptionButton(e.Graphics, b.Bounds);
                        }
                        else
                        {
                            //No background
                        }
                    }
                    else
                    {
                        if (b.Style == RibbonButtonStyle.DropDownListItem)
                        {
                            //clear out the drowdown background so we don't see the image area shading
                            using (SolidBrush br = new SolidBrush(ColorTable.DropDownBg))
                            {
                                //e.Graphics.Clear(Color.Transparent);
                                SmoothingMode sbuff = e.Graphics.SmoothingMode;
                                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
                                e.Graphics.FillRectangle(br, b.Bounds);
                                e.Graphics.SmoothingMode = sbuff;
                            }
                        }

                        if (b.DropDownPressed && b.SizeMode != RibbonElementSizeMode.DropDown)
                        {
                            DrawButtonPressed(e.Graphics, b, e.Ribbon);
                            DrawSplitButtonDropDownSelected(e, b);
                        }
                        else if (b.Pressed && b.SizeMode != RibbonElementSizeMode.DropDown)
                        {
                            DrawButtonPressed(e.Graphics, b, e.Ribbon);
                            DrawSplitButtonSelected(e, b);
                        }

                        else if (b.DropDownSelected)
                        {
                            DrawButtonSelected(e.Graphics, b, e.Ribbon);
                            DrawSplitButtonDropDownSelected(e, b);
                        }
                        else if (b.Selected)
                        {
                            DrawButtonSelected(e.Graphics, b, e.Ribbon);
                            DrawSplitButtonSelected(e, b);
                        }
                        else if (b.Checked)
                        {
                            DrawButtonChecked(e.Graphics, b, e.Ribbon);
                        }
                        else
                        {
                            DrawSplitButton(e, b);
                        }
                    }
                }




                if (b.Style != RibbonButtonStyle.Normal && !(b.Style == RibbonButtonStyle.DropDown && b.SizeMode == RibbonElementSizeMode.Large))
                {
                    if (b.Style == RibbonButtonStyle.DropDown)
                    {
                        DrawButtonDropDownArrow(e.Graphics, b, b.OnGetDropDownBounds(b.SizeMode, b.Bounds));
                    }
                    else
                    {
                        DrawButtonDropDownArrow(e.Graphics, b, b.DropDownBounds);
                    }
                }

                #endregion
            }
            else if (e.Item is RibbonItemGroup)
            {
                #region Group
                DrawItemGroup(e, e.Item as RibbonItemGroup);
                #endregion
            }
            else if (e.Item is RibbonButtonList)
            {
                #region ButtonList
                DrawButtonList(e.Graphics, e.Item as RibbonButtonList, e.Ribbon);
                #endregion
            }
            else if (e.Item is RibbonSeparator)
            {
                #region Separator
                if (e.Item.Visible)
                {
                    DrawSeparator(e.Graphics, e.Item as RibbonSeparator, e.Ribbon);
                }
                #endregion
            }
            else if (e.Item is RibbonUpDown)
            {
                #region UpDown

                RibbonUpDown t = e.Item as RibbonUpDown;

                if (t.Enabled)
                {
                    if (t != null && (t.Selected || (t.Editing)))
                    {
                        DrawTextBoxSelected(e.Graphics, t.TextBoxBounds);
                    }
                    else
                    {
                        DrawTextBoxUnselected(e.Graphics, t.TextBoxBounds);
                    }
                }
                else
                {
                    DrawTextBoxDisabled(e.Graphics, t.TextBoxBounds);
                }

                DrawUpDownButtons(e.Graphics, t, e.Ribbon);
                #endregion
            }
            else if (e.Item is RibbonComboBox)
            {
                #region RibbonComboBox

                RibbonComboBox c = e.Item as RibbonComboBox;

                if (c.Enabled)
                {
                    if (c != null && (c.Selected || c.DropDownVisible || c.Editing))
                    {
                        DrawTextBoxSelected(e.Graphics, c.TextBoxBounds);
                    }
                    else
                    {
                        DrawTextBoxUnselected(e.Graphics, c.TextBoxBounds);
                    }

                }
                else
                {
                    DrawTextBoxDisabled(e.Graphics, c.TextBoxBounds);
                }

                DrawComboxDropDown(e.Graphics, c, e.Ribbon);

                #endregion
            }
            else if (e.Item is RibbonTextBox)
            {
                #region TextBox

                RibbonTextBox t = e.Item as RibbonTextBox;

                if (t.Enabled)
                {
                    if (t != null && (t.Selected || (t.Editing)))
                    {
                        DrawTextBoxSelected(e.Graphics, t.TextBoxBounds);
                    }
                    else
                    {
                        DrawTextBoxUnselected(e.Graphics, t.TextBoxBounds);
                    }

                }
                else
                {
                    DrawTextBoxDisabled(e.Graphics, t.TextBoxBounds);
                }

                #endregion
            }
        }
 public override void OnRenderRibbonItemBorder(RibbonItemRenderEventArgs e)
 {
     if (e.Item is RibbonItemGroup)
     {
         DrawItemGroupBorder(e, e.Item as RibbonItemGroup);
     }
 }
        /// <summary>
        /// Draws the background of the specified  RibbonItemGroup
        /// </summary>
        /// <param name="e"></param>
        /// <param name="?"></param>
        public void DrawItemGroup(RibbonItemRenderEventArgs e, RibbonItemGroup grp)
        {

            if (e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2007)
            {
                Rectangle outerR = Rectangle.FromLTRB(
                     grp.Bounds.Left,
                     grp.Bounds.Top,
                     grp.Bounds.Right - 1,
                     grp.Bounds.Bottom - 1);

                Rectangle innerR = Rectangle.FromLTRB(
                     outerR.Left + 1,
                     outerR.Top + 1,
                     outerR.Right - 1,
                     outerR.Bottom - 1);

                Rectangle glossyR = Rectangle.FromLTRB(
                     outerR.Left + 1,
                     outerR.Top + outerR.Height / 2 + 1,
                     outerR.Right - 1,
                     outerR.Bottom - 1);

                GraphicsPath outer = RoundRectangle(outerR, 2);
                GraphicsPath inner = RoundRectangle(innerR, 2);
                GraphicsPath glossy = RoundRectangle(glossyR, 2);

                using (LinearGradientBrush b = new LinearGradientBrush(
                     innerR, ColorTable.ItemGroupBgNorth, ColorTable.ItemGroupBgSouth, 90))
                {
                    e.Graphics.FillPath(b, inner);
                }

                using (LinearGradientBrush b = new LinearGradientBrush(
                     glossyR, ColorTable.ItemGroupBgGlossy, Color.Transparent, 90))
                {
                    e.Graphics.FillPath(b, glossy);
                }

                outer.Dispose();
                inner.Dispose();
            }
        }
        /// <summary>
        /// Draws the background of the specified  RibbonItemGroup
        /// </summary>
        /// <param name="e"></param>
        /// <param name="?"></param>
        public void DrawItemGroupBorder(RibbonItemRenderEventArgs e, RibbonItemGroup grp)
        {

            if ((e.Ribbon.OrbStyle == RibbonOrbStyle.Office_2007) || e.Ribbon.IsDesignMode())
            {
                Rectangle outerR = Rectangle.FromLTRB(
                     grp.Bounds.Left,
                     grp.Bounds.Top,
                     grp.Bounds.Right - 1,
                     grp.Bounds.Bottom - 1);

                Rectangle innerR = Rectangle.FromLTRB(
                     outerR.Left + 1,
                     outerR.Top + 1,
                     outerR.Right - 1,
                     outerR.Bottom - 1);

                GraphicsPath outer = RoundRectangle(outerR, 2);
                GraphicsPath inner = RoundRectangle(innerR, 2);

                using (Pen dark = new Pen(ColorTable.ItemGroupSeparatorDark))
                {
                    using (Pen light = new Pen(ColorTable.ItemGroupSeparatorLight))
                    {
                        foreach (RibbonItem item in grp.Items)
                        {
                            if (item == grp.LastItem) break;

                            e.Graphics.DrawLine(dark,
                                 new Point(item.Bounds.Right, item.Bounds.Top),
                                 new Point(item.Bounds.Right, item.Bounds.Bottom - 1));

                            e.Graphics.DrawLine(light,
                                 new Point(item.Bounds.Right + 1, item.Bounds.Top),
                                 new Point(item.Bounds.Right + 1, item.Bounds.Bottom - 1));
                        }
                    }
                }

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

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

                outer.Dispose();
                inner.Dispose();
            }
        }
        /// <summary>
        /// Draws a SplitDropDown button with the dropdown area selected
        /// </summary>
        /// <param name="e"></param>
        /// <param name="button"></param>
        public void DrawSplitButtonDropDownSelected(RibbonItemRenderEventArgs e, RibbonButton button)
        {
            Rectangle outerR = Rectangle.FromLTRB(
                 button.DropDownBounds.Left,
                 button.DropDownBounds.Top,
                 button.DropDownBounds.Right - 1,
                 button.DropDownBounds.Bottom - 1);

            Rectangle innerR = Rectangle.FromLTRB(
                 outerR.Left + 1,
                 outerR.Top + (button.SizeMode == RibbonElementSizeMode.Large ? 1 : 0),
                 outerR.Right - 1,
                 outerR.Bottom - 1);

            Rectangle faceOuterR = Rectangle.FromLTRB(
                 button.ButtonFaceBounds.Left,
                 button.ButtonFaceBounds.Top,
                 button.ButtonFaceBounds.Right - 1,
                 button.ButtonFaceBounds.Bottom - 1);

            Rectangle faceInnerR = Rectangle.FromLTRB(
                 faceOuterR.Left + 1,
                 faceOuterR.Top + 1,
                 faceOuterR.Right + (button.SizeMode == RibbonElementSizeMode.Large ? -1 : 0),
                 faceOuterR.Bottom + (button.SizeMode == RibbonElementSizeMode.Large ? 0 : -1));

            Corners faceCorners = ButtonFaceRounding(button);
            Corners ddCorners = ButtonDdRounding(button);

            GraphicsPath outer = RoundRectangle(outerR, 3, ddCorners);
            GraphicsPath inner = RoundRectangle(innerR, 2, ddCorners);
            GraphicsPath faceOuter = RoundRectangle(faceOuterR, 3, faceCorners);
            GraphicsPath faceInner = RoundRectangle(faceInnerR, 2, faceCorners);

            using (SolidBrush b = new SolidBrush(Color.FromArgb(150, Color.White)))
            {
                e.Graphics.FillPath(b, faceInner);
            }

            using (Pen p = new Pen(button.Pressed && button.SizeMode != RibbonElementSizeMode.DropDown ? ColorTable.ButtonPressedBorderIn : ColorTable.ButtonSelectedBorderIn))
            {
                e.Graphics.DrawPath(p, faceInner);
            }

            using (Pen p = new Pen(button.Pressed && button.SizeMode != RibbonElementSizeMode.DropDown ? ColorTable.ButtonPressedBorderOut : ColorTable.ButtonSelectedBorderOut))
            {
                e.Graphics.DrawPath(p, faceOuter);
            }

            outer.Dispose(); inner.Dispose(); faceOuter.Dispose(); faceInner.Dispose();
        }
 /// <summary>
 /// Draws a SplitDropDown button with the dropdown area pressed
 /// </summary>
 /// <param name="e"></param>
 /// <param name="button"></param>
 public void DrawSplitButtonDropDownPressed(RibbonItemRenderEventArgs e, RibbonButton button)
 {
 }
 /// <summary>
 /// Draws a SplitDropDown button in normal state
 /// </summary>
 /// <param name="e"></param>
 /// <param name="button"></param>
 public void DrawSplitButton(RibbonItemRenderEventArgs e, RibbonButton button)
 {
 }
 /// <summary>
 /// Renders the border of the item, after the text and image of the item
 /// </summary>
 /// <param name="e"></param>
 public virtual void OnRenderRibbonItemBorder(RibbonItemRenderEventArgs e)
 {
 }
        public override void OnRenderRibbonItem(RibbonItemRenderEventArgs e)
        {
            if (e.Item is RibbonButton)
            {
                #region Button
                RibbonButton b = e.Item as RibbonButton;

                if (b.Enabled)
                {
                    if (b.Style == RibbonButtonStyle.Normal)
                    {
                        if (b.Pressed && b.SizeMode != RibbonElementSizeMode.DropDown)
                        {
                            DrawButtonPressed(e.Graphics, b);
                        }
                        else if (b.Selected)
                        {
                            if (b.Checked)
                            {
                                DrawButtonPressed(e.Graphics, b);
                            }
                            else
                            {
                                DrawButtonSelected(e.Graphics, b);
                            }
                        }
                        else if (b.Checked)
                        {
                            DrawButtonChecked(e.Graphics, b);
                        }
                        else if (b is RibbonOrbOptionButton)
                        {
                            DrawOrbOptionButton(e.Graphics, b.Bounds);
                        }
                        else
                        {
                            //No background
                        }
                    }
                    else
                    {

                        if (b.DropDownPressed && b.SizeMode != RibbonElementSizeMode.DropDown)
                        {
                            DrawButtonPressed(e.Graphics, b);
                            DrawSplitButtonDropDownSelected(e, b);
                        }
                        else if (b.Pressed && b.SizeMode != RibbonElementSizeMode.DropDown)
                        {
                            DrawButtonPressed(e.Graphics, b);
                            DrawSplitButtonSelected(e, b);
                        }

                        else if (b.DropDownSelected)
                        {
                            DrawButtonSelected(e.Graphics, b);
                            DrawSplitButtonDropDownSelected(e, b);
                        }
                        else if (b.Selected)
                        {
                            DrawButtonSelected(e.Graphics, b);
                            DrawSplitButtonSelected(e, b);
                        }
                        else if (b.Checked)
                        {
                            DrawButtonChecked(e.Graphics, b);
                        }
                        else
                        {
                            DrawSplitButton(e, b);
                        }
                    } 
                }

                if (b.Style != RibbonButtonStyle.Normal && !(b.Style == RibbonButtonStyle.DropDown && b.SizeMode == RibbonElementSizeMode.Large))
                {
                    if (b.Style == RibbonButtonStyle.DropDown)
                    {
                        DrawButtonDropDownArrow(e.Graphics, b, b.OnGetDropDownBounds(b.SizeMode, b.Bounds));
                    }
                    else
                    {
                        DrawButtonDropDownArrow(e.Graphics, b, b.DropDownBounds);
                    }
                }
                
                #endregion
            }
            else if (e.Item is RibbonItemGroup)
            {
                #region Group
                DrawItemGroup(e, e.Item as RibbonItemGroup);
                #endregion
            }
            else if (e.Item is RibbonButtonList)
            {
                #region ButtonList
                DrawButtonList(e.Graphics, e.Item as RibbonButtonList);
                #endregion
            }
            else if (e.Item is RibbonSeparator)
            {
                #region Separator
                DrawSeparator(e.Graphics, e.Item as RibbonSeparator);
                #endregion
            }
            else if (e.Item is RibbonTextBox)
            {
                #region TextBox

                RibbonTextBox t = e.Item as RibbonTextBox;

                if (t.Enabled)
                {
                    if (t != null && (t.Selected || (t.Editing)))
                    {
                        DrawTextBoxSelected(e.Graphics, t.TextBoxBounds);
                    }
                    else
                    {
                        DrawTextBoxUnselected(e.Graphics, t.TextBoxBounds);
                    }

                }
                else
                {
                    DrawTextBoxDisabled(e.Graphics, t.TextBoxBounds);
                }

                if (t is RibbonComboBox)
                {
                    DrawComboxDropDown(e.Graphics, t as RibbonComboBox);
                }

                #endregion
            }
            else if (e.Item is RibbonCheckBox)
            {
                #region CheckBox
                DrawCheckBox(e, e.Item as RibbonCheckBox);
                #endregion
            }
        }