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

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
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
// Full Unit code.
// -------------------------------------------------------------
// Create a new WinForm application, double click the form to
// create an OnLoad event, and then replace the WinForm unit
// with this text.
 
unit WinForm;
 
interface
 
uses
  System.Drawing, System.Collections, System.ComponentModel,
System.Windows.Forms, System.Data;
 
type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    ///
    /// Required designer variable.
    ///

    Components: System.ComponentModel.Container;
    ///
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///

    procedure InitializeComponent;
    procedure TWinForm_Load(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    ///
    /// Clean up any resources being used.
    ///

    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
  public
    constructor Create;
  end;
 
  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]
 
implementation
 
{$REGION 'Windows Form Designer generated code'}
///
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
///

 
 
procedure TWinForm.InitializeComponent;
begin
  //
  // TWinForm
  //
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
  Self.ClientSize := System.Drawing.Size.Create(292, 266);
  Self.Name := 'TWinForm';
  Self.Text := 'WinForm';
  Include(Self.Load, Self.TWinForm_Load);
end;
{$ENDREGION}
 
procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;
 
constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;
 
procedure TWinForm.TWinForm_Load(sender: System.Object; e: System.EventArgs);
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;
 
end.
Hide full unit code
   
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author