Lesson 31

Coloring Shapes

In this lesson, you will learn how to fill shapes with color in Visual Basic 2015 using Brush objects and Fill methods.

31.1 Introduction

In previous lessons, you learned how to draw shapes such as rectangles, ellipses, polygons, and pies using outlines. In this lesson, you will learn how to fill these shapes with color.

The main methods are:

  • FillRectangle
  • FillEllipse
  • FillPolygon
  • FillPie

To fill shapes, you must first create a Brush object:

Dim myBrush As Brush
myBrush = New SolidBrush(Color.Coral)

31.2 Filling a Rectangle

myGraphics.FillRectangle(myBrush, 65, 50, 150, 150)

Example 31.1

Private Sub BtnDraw_Click(...) Handles BtnDraw.Click

Dim myPen As Pen = New Pen(Color.Blue, 5)
Dim myBrush As Brush = New SolidBrush(Color.Coral)
Dim g As Graphics = Me.CreateGraphics()

g.DrawRectangle(myPen, 65, 50, 150, 150)
g.FillRectangle(myBrush, 65, 50, 150, 150)

End Sub

Figure 31.1 – Filled Rectangle

31.3 Filling an Ellipse

g.FillEllipse(myBrush, 50, 50, 180, 100)

Example 31.2

Dim myPen As New Pen(Color.Blue, 5)
Dim myBrush As New SolidBrush(Color.Coral)
Dim g As Graphics = Me.CreateGraphics()

g.DrawEllipse(myPen, 50, 50, 180, 100)
g.FillEllipse(myBrush, 50, 50, 180, 100)

Figure 31.2 – Filled Ellipse

31.4 Filling a Polygon

g.FillPolygon(myBrush, myPoints)

Example 31.3

Dim A As New Point(70, 10)
Dim B As New Point(170, 50)
Dim C As New Point(200, 150)
Dim D As New Point(140, 200)

Dim pts As Point() = {A, B, C, D}

Dim myPen As New Pen(Color.Blue, 5)
Dim myBrush As New SolidBrush(Color.Coral)
Dim g As Graphics = Me.CreateGraphics()

g.DrawPolygon(myPen, pts)
g.FillPolygon(myBrush, pts)

Figure 31.3 – Filled Polygon

31.5 Filling a Pie

g.FillPie(myBrush, 30, 40, 150, 150, 0, 60)

Example 31.4

Dim myPen As New Pen(Color.Blue, 5)
Dim myBrush As New SolidBrush(Color.Coral)
Dim g As Graphics = Me.CreateGraphics()

g.DrawPie(myPen, 30, 40, 150, 150, 0, 60)
g.FillPie(myBrush, 30, 40, 150, 150, 0, 60)

Figure 31.4 – Filled Pie

Build on This Foundation

Continue to VB2026

After learning the basics of checkbox controls in VB2015, move to the newest VB2026 tutorial for a more modern VB.NET learning path.

Explore VB2026 →

Visual Basic Programming

Visual Basic Programming

Use this Top Release book to reinforce your tutorial learning with a more structured guide.

Key Takeaways:
  • Use Brush to define fill color
  • FillRectangle, FillEllipse, FillPolygon, FillPie fill shapes
  • Combine Draw + Fill for outline + color
  • Without Draw → solid shape only

Next: Using Timer

Go to Lesson 32 →