Home

GDI+ Shapes: Ellipses and Circles

 

Description

An ellipse is a closed continuous line whose points are positioned so that two points exactly opposite each other have the exact same distant from a central point. It can be illustrated as follows:

Ellipse

Because an ellipse can fit in a rectangle, in GDI+ programming, an ellipse is defined with regards to a rectangle it would fit in. To draw an ellipse, you can use the Graphics.DrawEllipse() method that comes in four versions whose syntaxes are:

Public Sub DrawEllipse(pen As Pen, rect As Rectangle)
Public Sub DrawEllipse(pen As Pen, rect As RectangleF)
Public Sub DrawEllipse(pen As Pen, x As Integer, _
		    y As Integer, width As Integer, height As Integer)
Public Sub DrawEllipse(pen As Pen, x As Single, _
		    y As Single, width As Single, height As Single)

The arguments of this method play the same roll as those of the Graphics.DrawRectangle() method:

Ellipse 2

Here is an example:

Private Sub FormPaint(ByVal sender As Object, _
                              ByVal e As PaintEventArgs) _
                              Handles MyBase.Paint

            Dim penCurrent As Pen = New Pen(Color.Red)

            e.Graphics.DrawEllipse(penCurrent, New Rectangle(20, 20, 226, 144))

End Sub

Ellipse

 

Home Copyright © 2008-2012 FunctionX Home