Lesson 30: Drawing Polygon & Pie in VB2019
Master complex shapes with GDI+ using DrawPolygon and DrawPie methods
Key Takeaway
Visual Basic 2019 uses the DrawPolygon and DrawPie methods to create complex shapes by defining points and angles for precise geometric rendering.
After mastering text rendering in the previous lesson, we'll now explore how to draw polygons and pie shapes in VB2019. These advanced shapes allow you to create complex visual elements for your applications.
Polygon Fundamentals
Create multi-sided shapes by defining vertices
Pie Drawing
Create circular segments with precise angles
Point Structures
Define coordinates with Point objects
Pen Customization
Control line thickness and color
30.1 Drawing Polygons in VB2019
A polygon is a closed plane figure bounded by three or more straight sides. To draw a polygon in VB2019, you need to define the coordinates of all vertices and group them into a Point structure.
Polygon Drawing Fundamentals
The DrawPolygon method has the following syntax:
myGraphics.DrawPolygon(myPen, myPoints)
Parameter | Description | Required |
---|---|---|
myPen | Pen object defining line thickness and color | Yes |
myPoints | Array of Point objects defining vertices | Yes |
Creating Point Arrays
Point objects define the vertices of your polygon. You can create them individually and group them into an array:
' Define individual points Dim pointA As New Point(10, 10) Dim pointB As New Point(100, 50) Dim pointC As New Point(60, 150) ' Group points into an array Dim myPoints As Point() = {pointA, pointB, pointC}
Triangle
3-sided polygon
Quadrilateral
4-sided polygon
Example 30.1: Drawing a Triangle
This example creates a blue triangle with 5px thick lines:
Private Sub BtnDraw_Click(sender As Object, e As EventArgs) Handles BtnDraw.Click ' Create the Graphics object Dim myGraphics As Graphics = Me.CreateGraphics ' Define three points for the triangle Dim pointA As New Point(10, 10) Dim pointB As New Point(100, 50) Dim pointC As New Point(60, 150) ' Group points into an array Dim myPoints As Point() = {pointA, pointB, pointC} ' Create a blue pen with 5px thickness Dim myPen As New Pen(Drawing.Color.Blue, 5) ' Draw the triangle myGraphics.DrawPolygon(myPen, myPoints) End Sub

Figure 30.1: Triangle drawn with DrawPolygon
Example 30.2: Drawing a Quadrilateral
This example creates a quadrilateral with four vertices:
Private Sub BtnDraw_Click(sender As Object, e As EventArgs) Handles BtnDraw.Click ' Create the Graphics object Dim myGraphics As Graphics = Me.CreateGraphics ' Define four points for the quadrilateral Dim pointA As New Point(10, 10) Dim pointB As New Point(100, 50) Dim pointC As New Point(120, 150) Dim pointD As New Point(60, 200) ' Group points into an array Dim myPoints As Point() = {pointA, pointB, pointC, pointD} ' Create a blue pen with 5px thickness Dim myPen As New Pen(Drawing.Color.Blue, 5) ' Draw the quadrilateral myGraphics.DrawPolygon(myPen, myPoints) End Sub

Figure 30.2: Quadrilateral drawn with DrawPolygon
30.2 Drawing Pie Shapes
Pie shapes are circular segments defined by a bounding rectangle and start/sweep angles. In VB2019, you can draw pie shapes using the DrawPie method.
Pie Drawing Fundamentals
The DrawPie method has the following syntax:
myGraphics.DrawPie(myPen, X, Y, width, height, startAngle, sweepAngle)
Parameter | Description | Required |
---|---|---|
myPen | Pen object defining line thickness and color | Yes |
X, Y | Coordinates of the top-left corner of the bounding rectangle | Yes |
width, height | Dimensions of the bounding rectangle | Yes |
startAngle | Starting angle in degrees (0 = 3 o'clock position) | Yes |
sweepAngle | Angle to sweep (positive = clockwise, negative = counterclockwise) | Yes |
60° Pie Segment
Start: 0°, Sweep: 60°
120° Pie Segment
Start: 0°, Sweep: 120°
Example 30.3: Drawing a Pie Segment
This example creates a pie segment starting at 0° and sweeping clockwise through 60°:
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 blue pen with 5px thickness Dim myPen As New Pen(Drawing.Color.Blue, 5) ' Draw a pie segment ' (X, Y, width, height, startAngle, sweepAngle) myGraphics.DrawPie(myPen, 50, 50, 150, 150, 0, 60) End Sub

Figure 30.3: Pie segment drawn with DrawPie
Angle Direction | Effect | Example |
---|---|---|
Positive Sweep | Clockwise direction | DrawPie(..., 0, 90) |
Negative Sweep | Counter-clockwise direction | DrawPie(..., 0, -90) |
Lesson Summary
In this lesson, you've learned how to create complex shapes in VB2019:
DrawPolygon Method
Create multi-sided shapes by defining vertices
Point Structures
Define and group coordinates for polygon vertices
DrawPie Method
Create circular segments with precise angles
Angle Control
Control direction with positive/negative sweep angles
With polygon and pie shapes mastered, you're ready to explore coloring techniques. In the next lesson, we'll learn to fill shapes with colors.
Next Lesson
Learn to fill shapes with colors in Lesson 31: Coloring Shapes.
Related Resources

Visual Basic 2019 Made Easy
Master Visual Basic 2019 with this comprehensive guide that includes detailed coverage of polygon and pie drawing. Learn to create professional applications with complex shapes.
Key Graphics Topics:
- Polygon creation with DrawPolygon
- Pie segments with DrawPie
- Vertex definition and point structures
- Angle control for pie segments
- Practical projects with full source code

Visual Basic Programming With Code Examples
This comprehensive guide includes numerous examples of polygon and pie drawing in both VB6 and VB.NET, helping you understand the evolution of shape capabilities in Visual Basic.
Shape Drawing Coverage:
- 15+ polygon and pie examples
- Step-by-step shape tutorials
- Advanced geometry techniques
- Dynamic shape generation