Lesson 29

Drawing Text

In this lesson, you will learn how to draw text directly on the screen using the Graphics object, instead of using standard print or label controls.

29.1 Drawing Text

In previous lessons, you learned how to draw shapes such as rectangles and ellipses. Now, you will learn how to draw text using the DrawString method. :contentReference[oaicite:1]{index=1}

myGraphics.DrawString(myText, myFont, myBrush, X, Y)
  • myText → text to display
  • myFont → font style
  • myBrush → text color
  • X, Y → position

29.2 Creating Font

Dim myFont As New Font("Verdana", 20)

Font styles:

New Font("Verdana", 20, FontStyle.Bold)
New Font("Verdana", 20, FontStyle.Italic)
New Font("Verdana", 20, FontStyle.Underline)

29.3 Creating Brush

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

You can choose many colors such as Blue, Red, Aqua, DarkMagenta, etc.

29.4 Example 29.1

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

Dim g As Graphics = Me.CreateGraphics()
Dim font As New Font("Verdana", 20, FontStyle.Underline)
Dim brush As New SolidBrush(Color.DarkOrchid)

g.DrawString("Visual Basic 2015", font, brush, 10, 10)

End Sub

Figure 29.1 – Drawing Text Output

29.5 Simplified Method

You can simplify the code by using existing font and system brush:

g.DrawString("Visual Basic 2015", Me.Font, Brushes.DarkOrchid, 10, 10)

29.6 Example 29.2 - User Input

Dim g As Graphics = Me.CreateGraphics()
Dim userMsg As String

userMsg = InputBox("Enter your message")

Dim font As New Font("Verdana", 20, FontStyle.Underline)
Dim brush As New SolidBrush(Color.DarkOrchid)

g.DrawString(userMsg, font, brush, 10, 10)

This allows the user to display custom text dynamically.

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:
  • DrawString is used to display text
  • Font controls appearance
  • Brush controls color
  • Text can be dynamic using InputBox

Next: Drawing Polygon & Pie

Go to Lesson 30 →