示例#1
0
        /// <summary>
        /// Draws the glossy effect on the toolbar
        /// </summary>
        /// <param name="g"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        private void DrawGlossyEffect(Graphics g, ToolStrip t, int offset)
        {
            Rectangle glossyRect = new Rectangle(0, offset,
                                                 t.Width - 1,
                                                 (t.Height - 1) / 2);

            using (LinearGradientBrush b = new LinearGradientBrush(
                       glossyRect.Location, new PointF(0, glossyRect.Bottom),
                       ColorTable.GlossyEffectNorth,
                       ColorTable.GlossyEffectSouth))
            {
                using (GraphicsPath border =
                           GraphicsTools.CreateTopRoundRectangle(glossyRect, ToolStripRadius))
                {
                    g.FillPath(b, border);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Renders the background of a button on the specified rectangle using the specified device
        /// </summary>
        /// <param name="e"></param>
        private void DrawVistaButtonBackground(Graphics g, Rectangle r, bool selected, bool pressed, bool checkd)
        {
            g.SmoothingMode = SmoothingMode.AntiAlias;

            Rectangle outerBorder = new Rectangle(r.Left, r.Top, r.Width - 1, r.Height - 1);
            Rectangle border      = outerBorder; border.Inflate(-1, -1);
            Rectangle innerBorder = border; innerBorder.Inflate(-1, -1);
            Rectangle glossy      = outerBorder; glossy.Height /= 2;
            Rectangle fill        = innerBorder; fill.Height /= 2;
            Rectangle glow        = Rectangle.FromLTRB(outerBorder.Left,
                                                       outerBorder.Top + Convert.ToInt32(Convert.ToSingle(outerBorder.Height) * .5f),
                                                       outerBorder.Right, outerBorder.Bottom);

            if (selected || pressed || checkd)
            {
                #region Layers

                //Outer border
                using (GraphicsPath path =
                           GraphicsTools.CreateRoundRectangle(outerBorder, ButtonRadius))
                {
                    using (Pen p = new Pen(ColorTable.ButtonOuterBorder))
                    {
                        g.DrawPath(p, path);
                    }
                }

                //Checked fill
                if (checkd)
                {
                    using (GraphicsPath path = GraphicsTools.CreateRoundRectangle(innerBorder, 2))
                    {
                        using (Brush b = new SolidBrush(selected ? ColorTable.CheckedButtonFillHot : ColorTable.CheckedButtonFill))
                        {
                            g.FillPath(b, path);
                        }
                    }
                }

                //Glossy effefct
                using (GraphicsPath path = GraphicsTools.CreateTopRoundRectangle(glossy, ButtonRadius))
                {
                    using (Brush b = new LinearGradientBrush(
                               new Point(0, glossy.Top),
                               new Point(0, glossy.Bottom),
                               ColorTable.GlossyEffectNorth,
                               ColorTable.GlossyEffectSouth))
                    {
                        g.FillPath(b, path);
                    }
                }

                //Border
                using (GraphicsPath path =
                           GraphicsTools.CreateRoundRectangle(border, ButtonRadius))
                {
                    using (Pen p = new Pen(ColorTable.ButtonBorder))
                    {
                        g.DrawPath(p, path);
                    }
                }

                Color fillNorth = pressed ? ColorTable.ButtonFillNorthPressed : ColorTable.ButtonFillNorth;
                Color fillSouth = pressed ? ColorTable.ButtonFillSouthPressed : ColorTable.ButtonFillSouth;

                //Fill
                using (GraphicsPath path = GraphicsTools.CreateTopRoundRectangle(fill, ButtonRadius))
                {
                    using (Brush b = new LinearGradientBrush(
                               new Point(0, fill.Top),
                               new Point(0, fill.Bottom),
                               fillNorth, fillSouth))
                    {
                        g.FillPath(b, path);
                    }
                }

                Color innerBorderColor = pressed || checkd ? ColorTable.ButtonInnerBorderPressed : ColorTable.ButtonInnerBorder;

                //Inner border
                using (GraphicsPath path =
                           GraphicsTools.CreateRoundRectangle(innerBorder, ButtonRadius))
                {
                    using (Pen p = new Pen(innerBorderColor))
                    {
                        g.DrawPath(p, path);
                    }
                }

                //Glow
                using (GraphicsPath clip = GraphicsTools.CreateRoundRectangle(glow, 2))
                {
                    g.SetClip(clip, CombineMode.Intersect);

                    Color glowColor = ColorTable.Glow;

                    if (checkd)
                    {
                        if (selected)
                        {
                            glowColor = ColorTable.CheckedGlowHot;
                        }
                        else
                        {
                            glowColor = ColorTable.CheckedGlow;
                        }
                    }

                    using (GraphicsPath brad = CreateBottomRadialPath(glow))
                    {
                        using (PathGradientBrush pgr = new PathGradientBrush(brad))
                        {
                            unchecked
                            {
                                int        opacity = 255;
                                RectangleF bounds  = brad.GetBounds();
                                pgr.CenterPoint    = new PointF((bounds.Left + bounds.Right) / 2f, (bounds.Top + bounds.Bottom) / 2f);
                                pgr.CenterColor    = Color.FromArgb(opacity, glowColor);
                                pgr.SurroundColors = new Color[] { Color.FromArgb(0, glowColor) };
                            }
                            g.FillPath(pgr, brad);
                        }
                    }
                    g.ResetClip();
                }



                #endregion
            }
        }