logo search
CSharp_Graphics

Создание диагональных линейных градиентов

-----------------

How to: Create a Path Gradient

The PathGradientBrush class allows you to customize the way you fill a shape with gradually changing colors. For example, you can specify one color for the center of a path and another color for the boundary of a path. You can also specify separate colors for each of several points along the boundary of a path.

Note:

In GDI+, a path is a sequence of lines and curves maintained by a GraphicsPath object.

To fill an ellipse with a path gradient

By default, a path gradient brush does not extend outside the boundary of the path. If you use the path gradient brush to fill a figure that extends beyond the boundary of the path, the area of the screen outside the path will not be filled.

// Create a path that consists of a single ellipse.

GraphicsPath path = new GraphicsPath();

path.AddEllipse(0, 0, 140, 70);

// Use the path to construct a brush.

PathGradientBrush pthGrBrush = new PathGradientBrush(path);

// Set the color at the center of the path to blue.

pthGrBrush.CenterColor = Color.FromArgb(255, 0, 0, 255);

// Set the color along the entire boundary

// of the path to aqua.

Color[] colors = { Color.FromArgb(255, 0, 255, 255) };

pthGrBrush.SurroundColors = colors;

e.Graphics.FillEllipse(pthGrBrush, 0, 0, 140, 70);