Skip to content

Latest commit

 

History

History
55 lines (40 loc) · 3.86 KB

ellipses-and-arcs-in-gdi.md

File metadata and controls

55 lines (40 loc) · 3.86 KB
title description ms.date dev_langs helpviewer_keywords ms.assetid
Ellipses and Arcs in GDI+
Learn how to draw ellipses and arcs using the DrawEllipse and DrawArc methods in GDI+ with Windows Forms.
03/30/2017
csharp
vb
arcs
GDI+, arcs
drawing [Windows Forms], ellipses
GDI+, ellipses
ellipses
drawing [Windows Forms], arcs
34f35133-a835-4ca4-81f6-0dfedee8b683

Ellipses and Arcs in GDI+

You can easily draw ellipses and arcs using the xref:System.Drawing.Graphics.DrawEllipse%2A and xref:System.Drawing.Graphics.DrawArc%2A methods of the xref:System.Drawing.Graphics class.

Drawing an Ellipse

To draw an ellipse, you need a xref:System.Drawing.Graphics object and a xref:System.Drawing.Pen object. The xref:System.Drawing.Graphics object provides the xref:System.Drawing.Graphics.DrawEllipse%2A method, and the xref:System.Drawing.Pen object stores attributes, such as width and color, of the line used to render the ellipse. The xref:System.Drawing.Pen object is passed as one of the arguments to the xref:System.Drawing.Graphics.DrawEllipse%2A method. The remaining arguments passed to the xref:System.Drawing.Graphics.DrawEllipse%2A method specify the bounding rectangle for the ellipse. The following illustration shows an ellipse along with its bounding rectangle.

Screenshot of an ellipse surrounded by its bounding rectangle.

The following example draws an ellipse; the bounding rectangle has a width of 80, a height of 40, and an upper-left corner of (100, 50):

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

xref:System.Drawing.Graphics.DrawEllipse%2A is an overloaded method of the xref:System.Drawing.Graphics class, so there are several ways you can supply it with arguments. For example, you can construct a xref:System.Drawing.Rectangle and pass the xref:System.Drawing.Rectangle to the xref:System.Drawing.Graphics.DrawEllipse%2A method as an argument:

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

Drawing an Arc

An arc is a portion of an ellipse. To draw an arc, you call the xref:System.Drawing.Graphics.DrawArc%2A method of the xref:System.Drawing.Graphics class. The parameters of the xref:System.Drawing.Graphics.DrawArc%2A method are the same as the parameters of the xref:System.Drawing.Graphics.DrawEllipse%2A method, except that xref:System.Drawing.Graphics.DrawArc%2A requires a starting angle and sweep angle. The following example draws an arc with a starting angle of 30 degrees and a sweep angle of 180 degrees:

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

The following illustration shows the arc, the ellipse, and the bounding rectangle.

Screenshot of an ellipse with an arc and its bounding rectangle.

See also