Home  |  Delphi .net Home  |  System.Drawing.Graphics  |  FillPolygon Method
  
FillPolygon  
Method  
Creates a filled polygon shape defined by an array of points
Graphics Class
System.Drawing NameSpace
CF1.  Procedure FillPolygon ( Brush : System.Drawing.Brush; Points : Array of System.Drawing.Point ) ;
NotCF2.  Procedure FillPolygon ( Brush : System.Drawing.Brush; Points : Array of System.Drawing.PointF ) ;
NotCF3.  Procedure FillPolygon ( Brush : System.Drawing.Brush; Points : Array of System.Drawing.Point; FillMode : System.Drawing.Drawing2D.FillMode ) ;
NotCF4.  Procedure FillPolygon ( Brush : System.Drawing.Brush; Points : Array of System.Drawing.PointF; FillMode : System.Drawing.Drawing2D.FillMode ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The Points array of points defines a regular or irregular polygon shape. FillPolygon fills in the shape with the specified Brush.
 
Normally a polygon is deemed to be a shape with angles greater than 90 degrees (obtuse angles). However, a Microsoft polygon can have acute angles, and can overlap itself.
 
The FillMode optional parameter allows you to define how the fill process handles such an overlapping :
 
Alternate
Winding

 
Winding counts the number of lines crossed when radiating out from a point to determine if it is inside the shape. Alternate looks at curve intersections, and the directions each is drawn.
 
Microsoft MSDN Links
System.Drawing
System.Drawing.Graphics
 Author links

 
 
Drawing a red polygon and a yellow/blue hatched polygon
procedure TWinForm.TWinForm_Paint(sender: System.Object;
                                  e: System.Windows.Forms.PaintEventArgs);
var
  solidBrush : System.Drawing.SolidBrush;
  hatchBrush : System.Drawing.Drawing2D.HatchBrush;
  points     : Array[1..6] of System.Drawing.Point;

begin
  // Create the brushes
  solidBrush := System.Drawing.SolidBrush.Create(Color.Red);
  hatchBrush := System.Drawing.Drawing2D.HatchBrush.Create(HatchStyle.Vertical,
                                                           Color.Blue,
                                                           Color.Yellow);

  // Build the points array to form an elongated 6 sided polygon
  // Note that FillPolygon adds the final link line
  points[1] := Point.Create(10,  5);
  points[2] := Point.Create(20,  5);
  points[3] := Point.Create(25, 10);
  points[4] := Point.Create(20, 15);
  points[5] := Point.Create(10, 15);
  points[6] := Point.Create( 5, 10);

  // Draw this polygon using a solid red brush
  e.Graphics.FillPolygon(solidBrush, points);

  // Draw another polygon using a hatch brush
  points[1] := Point.Create(40,  5);
  points[2] := Point.Create(50,  5);
  points[3] := Point.Create(55, 10);
  points[4] := Point.Create(50, 15);
  points[5] := Point.Create(40, 15);
  points[6] := Point.Create(35, 10);

  e.Graphics.FillPolygon(hatchBrush, points);
end;
Show full unit code
   
Illustrating the two types of FillMode
procedure TWinForm.TWinForm_Paint(sender: System.Object;
                                  e: System.Windows.Forms.PaintEventArgs);
var
  solidBrush : System.Drawing.SolidBrush;
  points     : Array[1..10] of System.Drawing.Point;

begin
  // Create the brush
  solidBrush := System.Drawing.SolidBrush.Create(Color.Red);

  // Build the points array to form an overlapping polygon
  // Note that FillPolygon adds the final link line
  points[1]  := Point.Create( 5,  6);
  points[2]  := Point.Create(20,  6);
  points[3]  := Point.Create(20, 14);
  points[4]  := Point.Create(10, 14);
  points[5]  := Point.Create(10, 10);
  points[6]  := Point.Create(25, 10);
  points[7]  := Point.Create(25,  2);
  points[8]  := Point.Create(15,  2);
  points[9]  := Point.Create(15, 18);
  points[10] := Point.Create( 5, 18);

  // Draw this polygon using a solid red brush and winding filling
  e.Graphics.FillPolygon(solidBrush, points, FillMode.Winding);

  points[1]  := Point.Create(35,  6);
  points[2]  := Point.Create(50,  6);
  points[3]  := Point.Create(50, 14);
  points[4]  := Point.Create(40, 14);
  points[5]  := Point.Create(40, 10);
  points[6]  := Point.Create(55, 10);
  points[7]  := Point.Create(55,  2);
  points[8]  := Point.Create(45,  2);
  points[9]  := Point.Create(45, 18);
  points[10] := Point.Create(35, 18);

  // Draw this polygon using a solid blue brush and alternate filling
  solidBrush.Color := Color.Blue;
  e.Graphics.FillPolygon(solidBrush, points, FillMode.Alternate);
end;
Show full unit code
   
 
 
Delphi Programming Neil Moffatt All rights reserved.  |  Contact the author