Partilhar via


Filling a Shape with a Hatch Pattern

A hatch pattern is made from two colors: one for the background and one for the lines that form the pattern over the background. To fill a closed shape with a hatch pattern, use a HatchBrush object. The following example demonstrates how to fill an ellipse with a hatch pattern:

Dim hBrush As New HatchBrush( _
   HatchStyle.Horizontal, _
   Color.Red, _
   Color.FromArgb(255, 128, 255, 255))
e.Graphics.FillEllipse(hBrush, 0, 0, 100, 60)
[C#]
HatchBrush hBrush = new HatchBrush(
   HatchStyle.Horizontal,
   Color.Red, 
   Color.FromArgb(255, 128, 255, 255));
e.Graphics.FillEllipse(hBrush, 0, 0, 100, 60);

The following illustration shows the filled ellipse.

7eec8a36.hatch1(en-us,VS.71).gif

The HatchBrush constructor takes three arguments: the hatch style, the color of the hatch line, and the color of the background. The hatch style argument can be any value from the HatchStyle enumeration. There are more than fifty elements in the HatchStyle enumeration; a few of those elements are shown in the following list:

  • Horizontal
  • Vertical
  • ForwardDiagonal
  • HatchStyleBackwardDiagonal
  • HatchStyleCross
  • HatchStyleDiagonalCross