logo
CSharp_Graphics

Штриховые кисти

При заливке формы штриховой кистью необходимо задать основной цвет, цвет фона и стиль штриховки. Основной цвет определяет цвет штриховки.

HatchBrush myHatchBrush =

new HatchBrush(HatchStyle.Vertical, Color.Blue, Color.Green);

В GDI+ имеется более 50 стилей штриховки; на следующем рисунке показаны стили Horizontal, ForwardDiagonal и Cross.

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

Texture Brushes

With a texture brush, you can fill a shape with a pattern stored in a bitmap. For example, suppose the following picture is stored in a disk file named MyTexture.bmp.

The following code example shows how to fill an ellipse by repeating the picture stored in MyTexture.bmp.

Image myImage = Image.FromFile("MyTexture.bmp");

TextureBrush myTextureBrush = new TextureBrush(myImage);

myGraphics.FillEllipse(myTextureBrush, 0, 0, 100, 50);

The following illustration shows the filled ellipse.

Gradient Brushes

GDI+ provides two kinds of gradient brushes: linear and path. You can use a linear gradient brush to fill a shape with color that changes gradually as you move across the shape horizontally, vertically, or diagonally. The following code example shows how to fill an ellipse with a horizontal gradient brush that changes from blue to green as you move from the left edge of the ellipse to the right edge.

LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(

myRectangle,

Color.Blue,

Color.Green,

LinearGradientMode.Horizontal);

myGraphics.FillEllipse(myLinearGradientBrush, myRectangle);