Creating Graphics in Visual Basic 6
Master shape controls, drawing methods, and image handling for rich visual interfaces
Lesson Overview
Key Takeaway
VB6 provides powerful tools for creating graphics through shape controls, image boxes, and drawing methods, enabling you to build visually rich applications.
Welcome to Lesson 18 of our Visual Basic 6 Tutorial! In this lesson, you'll learn how to create compelling graphics in VB6. Unlike traditional BASIC where graphics required complex line-by-line programming, VB6 simplifies the process with intuitive controls and methods that make graphic design accessible to all developers.
18.1 The Line and Shape Controls
VB6 provides built-in controls for drawing basic shapes and lines directly on your forms. These controls are perfect for creating UI elements, diagrams, and visual separators.
Rectangle
Shape = 0
Square
Shape = 1
Oval
Shape = 2
Circle
Shape = 3
Rounded Rectangle
Shape = 4
Rounded Square
Shape = 5
To draw a shape:
- Select the Shape control from the toolbox
- Click and drag on the form to create your shape
- Modify properties like Shape, BorderStyle, FillStyle, and FillColor
18.1.1 Changing Shape Properties Programmatically
You can dynamically change shapes and colors using code. This example allows users to select a shape from a list and change its color:
Private Sub Form_Load() ' Add shape options to list List1.AddItem "Rectangle" List1.AddItem "Square" List1.AddItem "Oval" List1.AddItem "Circle" List1.AddItem "Rounded Rectangle" List1.AddItem "Rounded Square" End Sub Private Sub List1_Click() ' Change shape based on selection Select Case List1.ListIndex Case 0: Shape1.Shape = 0 ' Rectangle Case 1: Shape1.Shape = 1 ' Square Case 2: Shape1.Shape = 2 ' Oval Case 3: Shape1.Shape = 3 ' Circle Case 4: Shape1.Shape = 4 ' Rounded Rectangle Case 5: Shape1.Shape = 5 ' Rounded Square End Select End Sub Private Sub Command1_Click() ' Show color dialog and apply selection CommonDialog1.Flags = &H1& CommonDialog1.ShowColor Shape1.BackColor = CommonDialog1.Color End Sub
18.2 The Image Box and Picture Box
For more complex graphics, VB6 provides Image and Picture Box controls to display images in various formats.
Image Box
Lightweight control for displaying images with automatic resizing. Best for static images.
Picture Box
More powerful control that can contain other controls and supports drawing methods.
To load an image at runtime:
Loading Images
Picture1.Picture = LoadPicture("C:\path\to\image.jpg")
18.2.1 Random Image Display
This example demonstrates how to display random images using the Image Box control:
Dim a, b, c As Integer Private Sub Command1_Click() ' Generate random numbers a = 3 + Int(Rnd * 3) b = 3 + Int(Rnd * 3) c = 3 + Int(Rnd * 3) ' Set images based on random values If a = 3 Then Image1(0).Picture = LoadPicture("C:\Images\grape.gif") ElseIf a = 4 Then Image1(0).Picture = LoadPicture("C:\Images\cherry.gif") ElseIf a = 5 Then Image1(0).Picture = LoadPicture("C:\Images\orange.gif") End If ' Repeat for other image boxes ' ... End Sub
18.3 Drawing Methods: PSet, Line and Circle
For advanced graphics, VB6 provides drawing methods that allow you to create graphics programmatically.
Interactive Drawing Demo
Drawing Tools
Canvas Controls
PSet Method
Draws a single pixel at specified coordinates
Line Method
Draws lines and rectangles between points
Circle Method
Draws circles, ellipses, arcs and pie slices
18.3.1 Drawing Method Examples
Basic examples of using drawing methods:
' Draw a point at (100, 100) PSet (100, 100), vbRed ' Draw a line from (0,0) to (1000,2000) Line (0, 0)-(1000, 2000), vbBlue ' Draw a filled rectangle Line (500, 500)-(1500, 1500), vbGreen, BF ' Draw a circle at (1000,1000) with radius 500 Circle (1000, 1000), 500, vbMagenta
Lesson Summary
In this lesson, you've mastered VB6 graphics techniques:
Shape Controls
Using Line and Shape controls to create UI elements
Image Handling
Loading and displaying images with Image and Picture Boxes
Drawing Methods
Using PSet, Line, and Circle to create graphics programmatically
Dynamic Graphics
Changing properties and creating effects at runtime
Performance Tip
For complex animations, use the AutoRedraw property set to True to create persistent graphics that don't need to be redrawn when the form is obscured.
Practice Exercises
Test your graphics skills with these exercises:
Exercise 1: Shape Gallery
Create an application that displays all six VB6 shapes in different colors with labels.
Exercise 2: Image Viewer
Build an image viewer with navigation buttons to cycle through a folder of images.
Exercise 3: Drawing App
Create a simple drawing application using PSet and Line methods with mouse events.
Exercise 4: Animated Banner
Develop an animated banner using the Timer control and drawing methods.
Exercise 5: Pie Chart Generator
Create a program that generates pie charts from data using the Circle method.
Next Lesson
Continue your VB6 journey with Lesson 19: Creating a DVD Player Application.
Related Resources
Visual Basic 6 Made Easy
Start your programming journey with Visual Basic 6. Learn how to build Windows applications step-by-step using an easy and beginner-friendly approach.
- Perfect for beginners
- Learn core programming concepts
- Build real VB6 applications
Visual Basic 2026 Made Easy
Upgrade to modern Visual Basic with VB.NET, .NET 10, and Visual Studio 2026. Build real-world applications with modern tools and AI-powered development.
- Modern VB.NET development
- Hands-on projects and real apps
- GitHub Copilot & AI integration
๐ Ready for the Next Level?
After learning the basics with VB6 Made Easy and upgrading to VB2026 Made Easy, continue your journey into advanced professional development.
Advanced VB.NET Programming
Take your VB.NET skills to the next level. Learn advanced programming techniques, real-world architectures, and professional development practices using modern .NET.
Best For:
- After VB6 or VB.NET fundamentals
- Intermediate to advanced learners
- Developers building real-world systems
๐ Migrating from VB6 to VB.NET
Still using or learning classic Visual Basic 6? This practical step-by-step guide shows you how to migrate legacy VB6 applications to modern VB.NET with Visual Studio 2026 and .NET 10.
VB6 to Modern VB.NET Made Easy
A practical step-by-step guide to migrating legacy Visual Basic 6 applications to VB.NET with Visual Studio 2026 and .NET 10.
- Designed for VB6 programmers and legacy app maintainers
- Clear migration guidance from classic VB to modern .NET
- Perfect bridge between VB6 fundamentals and VB.NET development
๐ Move to Modern VB.NET
Visual Basic 6 is your foundation โ but modern development uses VB.NET with .NET and Visual Studio 2026.
Start VB.NET Tutorial โ