Compartilhar via


Ellipses and Arcs in GDI+

You can easily draw ellipses and arcs using the DrawEllipse and DrawArc methods of the Graphics class.

Drawing an Ellipse

To draw an ellipse, you need a Graphics object and a Pen object. The Graphics object provides the DrawEllipse method, and the Pen object stores attributes, such as width and color, of the line used to render the ellipse. The Pen object is passed as one of the arguments to the DrawEllipse method. The remaining arguments passed to the DrawEllipse 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):

myGraphics.DrawEllipse(myPen, 100, 50, 80, 40)
myGraphics.DrawEllipse(myPen, 100, 50, 80, 40);

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

Dim myRectangle As New Rectangle(100, 50, 80, 40)
myGraphics.DrawEllipse(myPen, myRectangle)
Rectangle myRectangle = new Rectangle(100, 50, 80, 40);
myGraphics.DrawEllipse(myPen, myRectangle);

Drawing an Arc

An arc is a portion of an ellipse. To draw an arc, you call the DrawArc method of the Graphics class. The parameters of the DrawArc method are the same as the parameters of the DrawEllipse method, except that DrawArc 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:

myGraphics.DrawArc(myPen, 100, 50, 140, 70, 30, 180)
myGraphics.DrawArc(myPen, 100, 50, 140, 70, 30, 180);

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

Ellipses and arcs

See Also

Tasks

How to: Create Graphics Objects for Drawing
How to: Create a Pen
How to: Draw an Outlined Shape

Reference

System.Drawing.Graphics
System.Drawing.Pen

Other Resources

Lines, Curves, and Shapes