Share via


Ellipses and Arcs

An ellipse is specified by its bounding rectangle. The following illustration shows an ellipse along with its bounding rectangle.

hk087c6d.aboutgdip02_art05(en-us,VS.71).gif

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 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)
[C#]
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 object and pass the Rectangle object to the DrawEllipse method as an argument:

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

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)
[C#]
myGraphics.DrawArc(myPen, 100, 50, 140, 70, 30, 180);

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

hk087c6d.aboutgdip02_art06(en-us,VS.71).gif