/// <summary>
 /// Gets the height that a separator should be on the DropDown
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 private int SeparatorHeight(RibbonSeparator s)
 {
     if (!string.IsNullOrEmpty(s.Text))
     {
         return(20);
     }
     else
     {
         return(3);
     }
 }
Beispiel #2
0
        public static void AddRibbonButton(Ribbon ribbon, 
                                           string tabText, 
                                           string buttonName,
                                           string text, 
                                           Image image, 
                                           string tooltip, 
                                           bool enable, 
                                           bool isChecked,
                                           RibbonButtonAlignment alignment,
                                           EventHandler clickHandler)
        {
            if (ribbon == null)
            {
                return;
            }

            RibbonItem ribbonItem = null;

            if (RibbonModulePluginProvider.Ribbon_Separator.Equals(buttonName))
            {
                ribbonItem = new RibbonSeparator();
            }
            else
            {
                ribbonItem = new RibbonButton();
                ribbonItem.Text = text;
                ribbonItem.Image = image;
                ribbonItem.ToolTip = tooltip;
                ribbonItem.Enabled = enable;
                ribbonItem.Checked = isChecked;
                ribbonItem.Click += new EventHandler(clickHandler);
            }

            ribbonItem.Name = buttonName;

            RibbonTab ribbonTab = RibbonHelper.FindRibbonTab(ribbon, tabText);

            if (ribbonTab == null)
            {
                return;
            }

            int panelIndex = alignment == RibbonButtonAlignment.Right ? 1 : 0;

            ribbonTab.Panels[panelIndex].Items.Add(ribbonItem);
        }
        public void DrawSeparator(Graphics g, RibbonSeparator separator, Ribbon ribbon)
        {
            #region Office_2007_2013

            if (ribbon.OrbStyle == RibbonOrbStyle.Office_2007 || ribbon.OrbStyle == RibbonOrbStyle.Office_2013)
            {
                if (separator.SizeMode == RibbonElementSizeMode.DropDown)
                {
                    // A horizontal separator on a dropdown menu
                    if (!string.IsNullOrEmpty(separator.Text))
                    {
                        using (SolidBrush b = new SolidBrush(ColorTable.SeparatorBg))
                        {
                            g.FillRectangle(b, separator.Bounds);
                        }

                        using (Pen p = new Pen(ColorTable.SeparatorLine))
                        {
                            g.DrawLine(p,
                                 new Point(separator.Bounds.Left, separator.Bounds.Bottom),
                                 new Point(separator.Bounds.Right, separator.Bounds.Bottom));
                        }
                    }
                    else
                    {
                        using (Pen p = new Pen(ColorTable.DropDownImageSeparator))
                        {
                            g.DrawLine(p,
                                new Point(separator.Bounds.Left + ((separator.DropDownWidth == RibbonSeparatorDropDownWidth.Full) ? 0 : 40), separator.Bounds.Top),
                                 new Point(separator.Bounds.Right, separator.Bounds.Top));
                        }
                    }
                }
                else
                {
                    // A vertical separator on  panel or QAT
                    if (separator.OwnerPanel == null)
                    {
                        // A vertical separator on the QAT
                        using (Pen p = new Pen(ColorTable.QATSeparatorDark))
                        {
                            g.DrawLine(p,
                                 new Point(separator.Bounds.Left + 1, separator.Bounds.Top + 5),
                                 new Point(separator.Bounds.Left + 1, separator.Bounds.Bottom - 1));
                        }

                        using (Pen p = new Pen(ColorTable.QATSeparatorLight))
                        {
                            g.DrawLine(p,
                                 new Point(separator.Bounds.Left + 2, separator.Bounds.Top + 5),
                                 new Point(separator.Bounds.Left + 2, separator.Bounds.Bottom - 1));
                        }
                    }
                    else
                    {
                        // A vertical separator on a Panel
                        using (Pen p = new Pen(ColorTable.SeparatorDark))
                        {
                            g.DrawLine(p,
                                 new Point(separator.Bounds.Left + 1, separator.Bounds.Top),
                                 new Point(separator.Bounds.Left + 1, separator.Bounds.Bottom));
                        }

                        using (Pen p = new Pen(ColorTable.SeparatorLight))
                        {
                            g.DrawLine(p,
                                 new Point(separator.Bounds.Left + 2, separator.Bounds.Top),
                                 new Point(separator.Bounds.Left + 2, separator.Bounds.Bottom));
                        }
                    }
                }
            }

            #endregion

            #region Office_2010

            if (ribbon.OrbStyle == RibbonOrbStyle.Office_2010)
            {
                if (separator.SizeMode == RibbonElementSizeMode.DropDown)
                {
                    // A horizontal separator on a dropdown menu
                    if (!string.IsNullOrEmpty(separator.Text))
                    {
                        using (SolidBrush b = new SolidBrush(ColorTable.SeparatorBg))
                        {
                            g.FillRectangle(b, separator.Bounds);
                        }

                        using (Pen p = new Pen(ColorTable.SeparatorLine))
                        {
                            g.DrawLine(p,
                                 new Point(separator.Bounds.Left, separator.Bounds.Bottom),
                                 new Point(separator.Bounds.Right, separator.Bounds.Bottom));
                        }
                    }
                    else
                    {
                        using (Pen p = new Pen(ColorTable.DropDownImageSeparator))
                        {
                            if (separator.DropDownWidth == RibbonSeparatorDropDownWidth.Partial)
                                p.DashStyle = DashStyle.Dash;
                            
                            g.DrawLine(p,
                                new Point(separator.Bounds.Left + ((separator.DropDownWidth == RibbonSeparatorDropDownWidth.Full) ? 0 : 40), separator.Bounds.Top),
                                 new Point(separator.Bounds.Right, separator.Bounds.Top));
                        }
                    }
                }
                else
                {
                    // A vertical separator on  panel or QAT
                    if (separator.OwnerPanel == null)
                    {
                        // A vertical separator on the QAT
                        using (Pen p = new Pen(ColorTable.QATSeparatorDark))
                        {
                            SmoothingMode smbuff = g.SmoothingMode;
                            g.SmoothingMode = SmoothingMode.None;
                            g.DrawLine(p,
                                 new Point(separator.Bounds.Left + 1, separator.Bounds.Top + 5),
                                 new Point(separator.Bounds.Left + 1, separator.Bounds.Bottom - 1));
                            g.SmoothingMode = smbuff;

                        }

                        using (Pen p = new Pen(ColorTable.QATSeparatorLight))
                        {
                            SmoothingMode smbuff = g.SmoothingMode;
                            g.SmoothingMode = SmoothingMode.None;
                            g.DrawLine(p,
                                 new Point(separator.Bounds.Left + 2, separator.Bounds.Top + 5),
                                 new Point(separator.Bounds.Left + 2, separator.Bounds.Bottom - 1));
                            g.SmoothingMode = smbuff;
                        }
                    }
                    else
                    {
                        // A vertical separator on a Panel
                        using (LinearGradientBrush blendBrush = new LinearGradientBrush(
                            new Point(separator.Bounds.Left, separator.Bounds.Top),
                            new Point(separator.Bounds.Left, separator.Bounds.Bottom),
                            Color.FromArgb(50, ColorTable.SeparatorDark),
                            ColorTable.SeparatorDark))
                        {
                            blendBrush.SetSigmaBellShape(0.5f);
                            using (Pen p = new Pen(blendBrush))
                            {
                                SmoothingMode sm = g.SmoothingMode;
                                g.SmoothingMode = SmoothingMode.None;
                                g.DrawLine(p, separator.Bounds.Left + 2, separator.Bounds.Top + 3, separator.Bounds.Left + 2, separator.Bounds.Bottom - 7);
                                g.SmoothingMode = sm;
                            }
                        }

                        using (LinearGradientBrush blendBrush = new LinearGradientBrush(
                            new Point(separator.Bounds.Left, separator.Bounds.Top),
                            new Point(separator.Bounds.Left, separator.Bounds.Bottom),
                            Color.FromArgb(50, ColorTable.SeparatorLight),
                            ColorTable.SeparatorLight))
                        {
                            blendBrush.SetSigmaBellShape(0.5f);
                            using (Pen p = new Pen(blendBrush))
                            {
                                SmoothingMode sm = g.SmoothingMode;
                                g.SmoothingMode = SmoothingMode.None;
                                g.DrawLine(p, separator.Bounds.Left + 1, separator.Bounds.Top + 3, separator.Bounds.Left + 1, separator.Bounds.Bottom - 7);
                                g.DrawLine(p, separator.Bounds.Left + 3, separator.Bounds.Top + 3, separator.Bounds.Left + 3, separator.Bounds.Bottom - 7);
                                g.SmoothingMode = sm;
                            }
                        }
                    }
                }
            }

            #endregion

        }
        public void DrawSeparator(Graphics g, RibbonSeparator separator)
        {
            if (separator.SizeMode == RibbonElementSizeMode.DropDown)
            {
                if (!string.IsNullOrEmpty(separator.Text))
                {
                    using (SolidBrush b = new SolidBrush(ColorTable.SeparatorBg))
                    {
                        g.FillRectangle(b, separator.Bounds);
                    }

                    using (Pen p = new Pen(ColorTable.SeparatorLine))
                    {
                        g.DrawLine(p,
                             new Point(separator.Bounds.Left, separator.Bounds.Bottom),
                             new Point(separator.Bounds.Right, separator.Bounds.Bottom));
                    }
                }
                else
                {
                    using (Pen p = new Pen(ColorTable.DropDownImageSeparator))
                    {
                        g.DrawLine(p,
                             new Point(separator.Bounds.Left + 30, separator.Bounds.Top + 1),
                             new Point(separator.Bounds.Right, separator.Bounds.Top + 1));
                    }
                }
            }
            else
            {
                using (Pen p = new Pen(ColorTable.SeparatorDark))
                {
                    g.DrawLine(p,
                         new Point(separator.Bounds.Left, separator.Bounds.Top),
                         new Point(separator.Bounds.Left, separator.Bounds.Bottom));
                }

                using (Pen p = new Pen(ColorTable.SeparatorLight))
                {
                    g.DrawLine(p,
                         new Point(separator.Bounds.Left + 1, separator.Bounds.Top),
                         new Point(separator.Bounds.Left + 1, separator.Bounds.Bottom));
                }
            }
        }
		/// <summary>
		/// Gets the height that a separator should be on the DropDown
		/// </summary>
		/// <param name="s"></param>
		/// <returns></returns>
		private int SeparatorHeight(RibbonSeparator s)
		{
			if (!string.IsNullOrEmpty(s.Text))
			{
				return 20;
			}
			else
			{
				return 3;
			}
		}
 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);
     }
 }
 private RibbonSeparator AddSeparator(RibbonItemCollection collection)
 {
     RibbonSeparator separator = new RibbonSeparator();
     collection.Add(separator);
     return separator;
 }