officefileapi-devexpress-dot-pdf-dot-pdfgraphics-dot-drawpolygon-x28-devexpress-dot-drawing-dot-dxpen-system-dot-drawing-dot-pointf-x29.md
Draws a polygon by points from the specified array.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Pdf.v25.2.Drawing.dll
NuGet Package : DevExpress.Pdf.Drawing
public void DrawPolygon(
DXPen pen,
PointF[] points
)
Public Sub DrawPolygon(
pen As DXPen,
points As PointF()
)
| Name | Type | Description |
|---|---|---|
| pen | DXPen |
A DXPen object that specifies the color, width, and style of the polygon.
| | points | PointF[] |
An array of PointF structures that specify the polygon vertices (in world coordinate system).
|
The first two points of the points array specify the first polygon side. Each next side connects the previous side’s end point and the next array point. If the first and last array points are different, they specify the last polygon side. Pass the points and pen parameters to the DrawPolygon method to draw a polygon.
To draw a shape on the PDF page, use one of the following methods:
PdfGraphics.AddToPageForeground, PdfGraphics.AddToPageBackgroundThese methods allow you to draw content on an existing page.PdfDocumentProcessor.RenderNewPageDraws content on a new page.
The following code snippet draws a polygon by seven points.
using DevExpress.Pdf;
using System.Drawing;
using DevExpress.Drawing;
//...
using (PdfDocumentProcessor processor = new PdfDocumentProcessor())
{
processor.CreateEmptyDocument();
PdfPage page = processor.AddNewPage(PdfPaperSize.A4);
using (PdfGraphics graphics = processor.CreateGraphicsWorldSystem())
{
// Create a point array.
PointF[] points = new PointF[]
{
new PointF(50, 50),
new PointF(200, 10),
new PointF(450, 150),
new PointF(500, 200),
new PointF(520, 350),
new PointF(570, 650),
new PointF(500, 700)
};
// Draw a polygon.
using (var pen = new DXPen(Color.Red, 5))
graphics.DrawPolygon(pen, points);
// Add graphics content to the document page.
graphics.AddToPageForeground(page);
}
processor.SaveDocument("out2.pdf");
}
Process.Start("out.pdf");
Imports DevExpress.Pdf
Imports System.Drawing
Imports DevExpress.Drawing
'...
Using processor As New PdfDocumentProcessor()
processor.CreateEmptyDocument()
Dim page As PdfPage = processor.AddNewPage(PdfPaperSize.A4)
Using graphics As PdfGraphics = processor.CreateGraphicsWorldSystem()
' Create a point array.
Dim points() As PointF = {
New PointF(50, 50),
New PointF(200, 10),
New PointF(450, 150),
New PointF(500, 200),
New PointF(520, 350),
New PointF(570, 650),
New PointF(500, 700)
}
' Draw a polygon.
Using pen As New DXPen(Color.Red, 5)
graphics.DrawPolygon(pen, points)
End Using
' Add graphics content to the document page.
graphics.AddToPageForeground(page)
End Using
processor.SaveDocument("out2.pdf")
End Using
Process.Start("out.pdf")
See Also