// Gradient Fills
        public override void DrawGradientRectangle(GradientRect gRect)
        {
            BufferChunk chunk = new BufferChunk(1024);

            chunk += GDI32.EMR_GRADIENTFILL;

            // Pack the vertices
            Pack(chunk, gRect.Vertices);

            // Pack the gradient mesh
            Pack(chunk, gRect.Boundary);

            // pack the mode
            chunk += (int)gRect.Direction;

            PackCommand(chunk);
        }
Ejemplo n.º 2
0
        public static void GradientFill(Graphics graphics, Rectangle target,
                                        Color startColor, Color endColor,
                                        GradientDirection direction)
        {
            if (!GradientFillSupported)
            {
                return;
            }

            var hdc = graphics.GetHdc();

            try
            {
                var vertices = new TriVertex[]
                {
                    new TriVertex(target.Left, target.Top, startColor),
                    new TriVertex(target.Right, target.Bottom, endColor)
                };
                var rectangles = new GradientRect[]
                {
                    new GradientRect()
                    {
                        UpperLeft  = 0,
                        LowerRight = 1
                    }
                };

                GradientFill(hdc, vertices, 2, rectangles, 1,
                             direction == GradientDirection.Horizontal ?
                             GRADIENT_FILL_RECT_H : GRADIENT_FILL_RECT_V);
            }
            finally
            {
                graphics.ReleaseHdc(hdc);
            }
        }