Files
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

3.7 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
Ellipses and Arcs in GDI+ 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.

Ellipses and arcs

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.

Ellipses and arcs

See also