ARTICLE

Drawing Ellipses and Circles in GDI+

Posted by Dinesh Beniwal Articles | GDI+ in VB.NET November 17, 2009
In this article I will explain you how to draw Ellipses and Circles in GDI+.
Download Files:
 
Reader Level:


Ellipse1.JPG

FIGURE 3.5: An ellipse

Drawing Ellipses and Circles

An ellipse is a circular boundary within a rectangle, where each opposite point has the same distance from a fixed point, called the center of the ellipse. An ellipse within a square is called a circle. Figure 3.5 shows an ellipse with its height, width, and center indicated.

To draw an ellipse, you need to specify the outer rectangle. GDI+ takes care of the rest. DrawEllipse draws an ellipse defined by a rectangle specified by a pair of coordinates, a height, and a width (an ellipse with equal height and width is a circle).

To draw an ellipse, an application creates a pen and four coordinates (or a rectangle), and then calls DrawEllipse. Listing 3.5 draws ellipses with different options.

LISTING 3.5: Drawing ellipses


    Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
       
' Create Pens
        Dim redPen As New Pen(Color.Red, 6)
        Dim bluePen As New Pen(Color.Blue, 4)
        Dim greenPen As New Pen(Color.Green, 2)
       
' Create a rectangle
        Dim rect As New Rectangle(80, 80, 50, 50)
       
' Draw ellipses
        e.Graphics.DrawEllipse(greenPen, 100.0F, 100.0F, 10.0F, 10.0F)
        e.Graphics.DrawEllipse(redPen, rect)
        e.Graphics.DrawEllipse(bluePen, 60, 60, 90, 90)
        e.Graphics.DrawEllipse(greenPen, 40.0F, 40.0F, 130.0F, 130.0F)
       
'Dispose of objects
        redPen.Dispose()
        greenPen.Dispose()
        bluePen.Dispose()
    End Sub

Figure 3.6 shows the output from Listing 3.5

Ellipse2.JPG

FIGURE 3.6: Drawing ellipse

Conclusion

Hope the article would have helped you in understanding drawing Ellipses and Circles in GDI+. Read other articles on GDI+ on the website.
 

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Diagram
Become a Sponsor