Lesson 28: Drawing Ellipses & Circles in VB2019
Master circular shapes with GDI+ using DrawEllipse method
Key Takeaway
Visual Basic 2019 uses the DrawEllipse method for both ellipses and circles, with circles being a special case where width and height are equal.
Building on the rectangle drawing techniques from the previous lesson, we'll now explore how to draw ellipses and circles in VB2019. These curved shapes are essential for creating everything from UI elements to game graphics.
Ellipse Fundamentals
Ellipses are defined by their bounding rectangles
Rectangle Objects
Create reusable Rectangle objects for consistent shapes
Direct Coordinates
Draw without creating rectangle objects
Circle Creation
Simply set width and height equal
28.1 Drawing Ellipses in VB2019
In Visual Basic 2019, you can draw ellipses using two primary methods similar to rectangles. Both approaches leverage the Graphics and Pen objects.
Method 1: Rectangle Object
First create a Rectangle object, then draw the ellipse using the DrawEllipse method.
Where:
- X, Y: Coordinates of the upper-left corner
- width: Width of the bounding rectangle
- height: Height of the bounding rectangle
Method 2: Direct Drawing
Draw an ellipse directly by specifying its bounding rectangle coordinates.
Benefits:
- More concise for single-use shapes
- Faster implementation
- Simpler code for simple drawings
Ellipse Drawing: Rectangle Object Method
This example creates a turquoise ellipse with a 5-pixel border using a Rectangle object:
Private Sub BtnDraw_Click(sender As Object, e As EventArgs) Handles BtnDraw.Click ' Create the Graphics object Dim myGraphics As Graphics = Me.CreateGraphics ' Create a turquoise pen with 5px width Dim myPen As New Pen(Drawing.Color.DarkTurquoise, 5) ' Create a rectangle object Dim myRectangle As New Rectangle(40, 30, 200, 100) ' Draw the ellipse myGraphics.DrawEllipse(myPen, myRectangle) End Sub

Figure 28.1: Ellipse drawn using rectangle object method
Ellipse Drawing: Direct Method
This approach draws an ellipse without creating a separate Rectangle object:
Private Sub BtnDraw_Click(sender As Object, e As EventArgs) Handles BtnDraw.Click ' Create the Graphics object Dim myGraphics As Graphics = Me.CreateGraphics ' Create a turquoise pen with 5px width Dim myPen As New Pen(Drawing.Color.DarkTurquoise, 5) ' Draw ellipse at (40,30) with width=200, height=100 myGraphics.DrawEllipse(myPen, 40, 30, 200, 100) End Sub
The direct method approach is particularly useful when:
- You need to draw a single ellipse quickly
- Your coordinates are already defined
- You want to minimize code complexity
28.2 Drawing Circles
In VB2019, circles are simply a special case of ellipses where the width and height of the bounding rectangle are equal. The same DrawEllipse method is used for both shapes.
Circle Drawing: Rectangle Object Method
This example creates a circle by setting the rectangle's width and height equal:
Private Sub BtnDraw_Click(sender As Object, e As EventArgs) Handles BtnDraw.Click ' Create the Graphics object Dim myGraphics As Graphics = Me.CreateGraphics ' Create a turquoise pen with 5px width Dim myPen As New Pen(Drawing.Color.DarkTurquoise, 5) ' Create a square rectangle for the circle Dim myRectangle As New Rectangle(90, 30, 100, 100) ' Draw the circle myGraphics.DrawEllipse(myPen, myRectangle) End Sub

Figure 28.2: Circle drawn using rectangle object method
Circle Drawing: Direct Method
This approach draws a circle without creating a separate Rectangle object:
Private Sub BtnDraw_Click(sender As Object, e As EventArgs) Handles BtnDraw.Click ' Create the Graphics object Dim myGraphics As Graphics = Me.CreateGraphics ' Create a turquoise pen with 5px width Dim myPen As New Pen(Drawing.Color.DarkTurquoise, 5) ' Draw circle at (90,30) with width=100, height=100 myGraphics.DrawEllipse(myPen, 90, 30, 100, 100) End Sub
Method | Best For | Performance | Code Complexity |
---|---|---|---|
Rectangle Object | Reusable shapes, complex designs | Optimal for multiple shapes | Slightly higher |
Direct Drawing | Single shapes, simple projects | Faster for one-off shapes | Lower |
Lesson Summary
In this lesson, you've learned how to create ellipses and circles in VB2019:
Ellipse Fundamentals
Ellipses are defined by their bounding rectangles
Rectangle Objects
Create reusable Rectangle objects for consistent shapes
Direct Drawing
Draw ellipses directly without creating rectangle objects
Circle Creation
Set width and height equal to create perfect circles
With ellipse and circle drawing mastered, you're ready to explore more complex shapes. In the next lesson, we'll learn to draw text and create custom fonts.
Next Lesson
Learn to draw text and customize fonts in Lesson 29: Drawing Text.
Related Resources

Visual Basic 2019 Made Easy
Master Visual Basic 2019 with this comprehensive guide that includes detailed coverage of graphics programming. Learn to create professional applications with custom graphics and visual elements.
Key Graphics Topics:
- Drawing shapes: rectangles, ellipses, polygons, and more
- Working with colors, gradients, and textures
- Creating animations with the Timer control
- Building custom UI elements with graphics
- Practical projects with full source code

Visual Basic Programming With Code Examples
This comprehensive guide includes numerous examples of graphics programming in both VB6 and VB.NET, helping you understand the evolution of graphics capabilities in Visual Basic.
Graphics Coverage:
- 20+ graphics programming examples
- Step-by-step drawing tutorials
- Custom control creation with graphics
- Animation techniques and examples