Ejemplo n.º 1
0
        public void GradientFillShape(Rectangle rect, int radius, Color startColor, Color endColor, GradientMode gradientMode, GraphicShape shape, RoundedCorners corners)
        {
            if (rect.Width < 1 || rect.Height < 1) return;
            PathFunc func = GetShapeFunc(shape);
            SmoothingMode mode = SmoothingMode;
            try
            {
                SmoothingMode = SmoothingMode.None;
                int x = rect.X, y = rect.Y, w = rect.Width, h = rect.Height;
                int reflectionHeight = h / 2;

                PointF p1 = new PointF(x, y);
                PointF p2 = new PointF(x, y + reflectionHeight);

                if (gradientMode == GradientMode.Top)
                {
                    PathMode pathMode = endColor.A == 255 ? PathMode.Bottom : PathMode.All;
                    using (GraphicsPath path = func(rect, radius, reflectionHeight, pathMode, corners))
                    {
                        using (SolidBrushPlus brush = new SolidBrushPlus(endColor))
                        {
                            this.FillPath(brush, path);
                        }
                    }
                    using (GraphicsPath path = func(rect, radius, reflectionHeight, PathMode.Top, corners))
                    {
                        using (LinearGradientBrush brush = new LinearGradientBrush(p1, p2, startColor, endColor))
                        {
                            this.FillPath(brush, path);
                        }
                    }
                }
                else
                {
                    PathMode pathMode = endColor.A == 255 ? PathMode.Top : PathMode.All;
                    using (GraphicsPath path = func(rect, radius, reflectionHeight, PathMode.All, corners))
                    {
                        using (SolidBrushPlus brush = new SolidBrushPlus(endColor))
                        {
                            this.FillPath(brush, path);
                        }
                    }
                    using (GraphicsPath path = func(rect, radius, reflectionHeight, PathMode.Bottom, corners))
                    {
                        p1.Y = y + reflectionHeight - 1;
                        p2.Y = y + h;
                        using (LinearGradientBrush brush = new LinearGradientBrush(p1, p2, endColor, startColor))
                        {
                            this.FillPath(brush, path);
                        }
                    }
                }
            }
            finally
            {
                SmoothingMode = mode;
            }
        }
Ejemplo n.º 2
0
        public void PaintHeaderBackground()
        {
            Graphics g = Graphics;
            Rectangle r = ClientBounds;

            Color color = BackColor;
            Color startColor = ColorConverter.AlphaBlendColor(Color.White, color, 100);
            if (IsTransparent)
            {
                color = ColorConverter.AlphaColor(color, 200);
                startColor = ColorConverter.AlphaColor(startColor, 150);
                using (GraphicsPlus gp = new GraphicsPlus(g))
                {
                    PointF p1 = new PointF(r.X, r.Y);
                    PointF p2 = new PointF(r.X, r.Bottom);
                    using (LinearGradientBrush backGround = new LinearGradientBrush(p1, p2, startColor, color))
                    {
                        gp.FillRectangle(backGround, r);
                    }
                }
            }
            else
            {
                GdiExt.GradientFill(g, r, startColor, color, GdiExt.FillDirection.TopToBottom);
            }
        }