Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 4.48 KB

open-and-closed-curves-in-gdi.md

File metadata and controls

55 lines (39 loc) · 4.48 KB
title description ms.date dev_langs helpviewer_keywords ms.assetid
Open and Closed Curves in GDI+
Learn more about how GDI+ can create open and closed curves with the Graphics class and its methods.
03/30/2017
csharp
vb
curves [Windows Forms], filling
GDI+, curves
curves [Windows Forms], drawing
curves
08d2cc9a-dc9d-4eed-bcbb-2c8e2ca5d3ae

Open and Closed Curves in GDI+

The following illustration shows two curves: one open and one closed.

Screenshot of one open curve and one closed curve.

Managed Interface for Curves

Closed curves have an interior and therefore can be filled with a brush. The xref:System.Drawing.Graphics class in GDI+ provides the following methods for filling closed shapes and curves: xref:System.Drawing.Graphics.FillRectangle%2A, xref:System.Drawing.Graphics.FillEllipse%2A, xref:System.Drawing.Graphics.FillPie%2A, xref:System.Drawing.Graphics.FillPolygon%2A, xref:System.Drawing.Graphics.FillClosedCurve%2A, xref:System.Drawing.Graphics.FillPath%2A, and xref:System.Drawing.Graphics.FillRegion%2A. Whenever you call one of these methods, you must pass one of the specific brush types (xref:System.Drawing.SolidBrush, xref:System.Drawing.Drawing2D.HatchBrush, xref:System.Drawing.TextureBrush, xref:System.Drawing.Drawing2D.LinearGradientBrush, or xref:System.Drawing.Drawing2D.PathGradientBrush) as an argument.

The xref:System.Drawing.Graphics.FillPie%2A method is a companion to the xref:System.Drawing.Graphics.DrawArc%2A method. Just as the xref:System.Drawing.Graphics.DrawArc%2A method draws a portion of the outline of an ellipse, the xref:System.Drawing.Graphics.FillPie%2A method fills a portion of the interior of an ellipse. The following example draws an arc and fills the corresponding portion of the interior of the ellipse:

[!code-csharpLinesCurvesAndShapes#21] [!code-vbLinesCurvesAndShapes#21]

The following illustration shows the arc and the filled pie.

Screenshot of an arc and the filled pie.

The xref:System.Drawing.Graphics.FillClosedCurve%2A method is a companion to the xref:System.Drawing.Graphics.DrawClosedCurve%2A method. Both methods automatically close the curve by connecting the ending point to the starting point. The following example draws a curve that passes through (0, 0), (60, 20), and (40, 50). Then, the curve is automatically closed by connecting (40, 50) to the starting point (0, 0), and the interior is filled with a solid color.

[!code-csharpLinesCurvesAndShapes#22] [!code-vbLinesCurvesAndShapes#22]

The xref:System.Drawing.Graphics.FillPath%2A method fills the interiors of the separate pieces of a path. If a piece of a path doesn't form a closed curve or shape, the xref:System.Drawing.Graphics.FillPath%2A method automatically closes that piece of the path before filling it. The following example draws and fills a path that consists of an arc, a cardinal spline, a string, and a pie:

[!code-csharpLinesCurvesAndShapes#23] [!code-vbLinesCurvesAndShapes#23]

The following illustration shows the path with and without the solid fill. Note that the text in the string is outlined, but not filled, by the xref:System.Drawing.Graphics.DrawPath%2A method. It is the xref:System.Drawing.Graphics.FillPath%2A method that paints the interiors of the characters in the string.

String in a path

See also