Lesson 3 Β· VB6 Tutorial

Working with Controls in Visual Basic 6

Master essential VB6 controls, configure properties, write event procedures, and build interactive Windows applications with TextBox, Label, CommandButton, ListBox, ComboBox, CheckBox, OptionButton, PictureBox, Image, and Shape controls.

Lesson reading progress

Lesson Overview

Lesson3 of 40
TopicVB6 Controls and Interface Design
FocusProperties Β· Events Β· UI Controls
GoalBuild Interactive VB6 Forms
Upgrade PathVB.NET / Visual Studio 2026

Key Takeaway

VB6 controls are the building blocks of your application's user interface. Understanding how to configure properties and handle events is essential for creating interactive and professional Windows applications.

Welcome to Lesson 3 of our Visual Basic 6 Tutorial! In this lesson, you'll learn how to work with essential VB6 controls to create interactive applications. We'll cover TextBoxes, Labels, CommandButtons, ListBoxes, ComboBoxes, and more, with practical examples you can implement.

3.1 The Control Properties

To create effective event procedures, you need to configure specific properties that dictate a control's appearance and functionality. These properties can be set either through the properties window or dynamically at runtime.

Properties Window of VB6 IDE
Figure 3.1: The Properties Window in VB6 IDE

In the properties window, the top section shows the currently selected object. The bottom is divided into columnsβ€”the left lists properties, and the right displays their current states. To modify, simply adjust the items in the right column.

1 Changing Properties

Change the form caption by highlighting 'Form1' and entering your text. Customize appearance by selecting 3D/flat style, colors, fonts, and enabling/disabling controls.

2 Runtime Property Changes

You can change properties at runtime to create effects like color changes, animations, and more. VB uses hexadecimal color codes which can be found in properties windows.

Changing Background Color at Runtime

This example changes the background color of the form to red when loaded:

ColorChange.vb
Private Sub Form_Load()
    Form1.Show
    Form1.BackColor = &H000000FF&
End Sub

Output:

Changing Shape at Runtime

This code changes a shape control to a circle at runtime:

ShapeChange.vb
Private Sub Form_Load()
    Shape1.Shape = 3 
End Sub

Important Property Tips

  • Set the Caption property clearly so users understand the control's function
  • Use meaningful names for the Name property for easier coding and debugging
  • Consider when to enable/disable controls using the Enabled property
  • Use the Visible property to show/hide controls when appropriate

3.2 Handling Common Controls

VB6 Toolbox
Figure 3.2: The VB6 Toolbox with Essential Controls

TextBox

Standard control for user input and displaying output. Handles text and numeric data.

Label

Provides instructions and displays output. The Caption property is most important.

CommandButton

Executes procedures triggered by user events, most commonly the Click event.

PictureBox

Handles graphics. Can load pictures at design time or runtime with LoadPicture.

3.2.1 The TextBox Control

The text box accepts input from users and displays output. It handles string and numeric data. Use Val(text) to convert string input to numeric data.

Example: Summation of Two Numbers

This program adds numbers entered in two text boxes and displays the result in a label:

Addition.vb
Private Sub Command1_Click()
    ' Add values from TextBox1 and TextBox2
    Dim Sum As Double
    Sum = Val(Text1.Text) + Val(Text2.Text)
    
    ' Display the result in Label1
    Label1.Caption = Sum
End Sub

Output:

Summation program output
Figure 3.3: Summation Program Output

3.2.2 The Label Control

Labels provide instructions and display outputs. The Caption property is essential and can be changed at runtime.

3.2.3 The CommandButton Control

Command buttons execute procedures, typically in response to a Click event:

ButtonClick.vb
Private Sub Command1_Click()
    ' Code to execute when button is clicked
    ' ...
End Sub

Example: Simple Password Display Demo

This program reveals a password entered in a text box with PasswordChar set to '*':

PasswordDisplay.vb
Private Sub cmd_ShowPass_Click()
    Dim yourpassword As String
    yourpassword = Txt_Password.Text
    MsgBox ("Your password is: " & yourpassword)
End Sub

Output:

Password cracker application
Figure 3.4: Password Display Demo Application

3.2.4 The PictureBox Control

The PictureBox handles graphics. Load images at design time through properties or at runtime with LoadPicture:

LoadImage.vb
Private Sub cmd_LoadPic_Click()
    Picture1.Picture = LoadPicture("C:\Path\To\Your\Image.jpg")
End Sub
Picture viewer application
Figure 3.5: Picture Viewer Application

3.2.5 The Image Control

Similar to PictureBox but with a key difference - images in an ImageBox are stretchable. Use the same LoadPicture method:

Image control example
Figure 3.6: Image Control with Stretch Property Enabled

3.2.6 The ListBox Control

Presents a list of items for user selection. Add items with the AddItem method:

ListBoxExample.vb
Private Sub Form_Load()
    List1.AddItem "Lesson1"
    List1.AddItem "Lesson2"
    List1.AddItem "Lesson3"
    List1.AddItem "Lesson4"
End Sub
ListBox control
Figure 3.7: ListBox with Items Added

3.2.7 The ComboBox Control

Similar to ListBox but presents items in a drop-down list. Add items with AddItem:

ComboBox control
Figure 3.8: ComboBox with Dropdown Items

3.2.8 The CheckBox Control

Lets users select or deselect options. Value is 1 when checked and 0 when unchecked:

CheckBox control
Figure 3.9: CheckBox Control Example

3.2.9 The OptionButton Control

Option buttons work together - when one is selected, others are deselected. Value is True when selected:

OptionButtons.vb
Private Sub cmd_SetColor_Click()
    If Option1.Value = True Then
        Form1.BackColor = vbRed
    ElseIf Option2.Value = True Then
        Form1.BackColor = vbBlue
    Else
        Form1.BackColor = vbGreen
    End If
End Sub

3.2.10 The Shape Control

Displays various shapes. Shape property values: 0=rectangle, 1=square, 2=oval, 3=circle, 4=rounded rectangle, 5=rounded square.

Shape control example
Figure 3.10: Shape Control with Different Shapes

Lesson Summary

In this lesson, you learned how to work with essential VB6 controls and how those controls help you build interactive Windows applications.

Control Properties

You learned how properties such as Caption, Name, BackColor, Enabled, and Visible affect the appearance and behavior of controls.

Input and Output Controls

You used TextBox for user input and Label for displaying calculated or status output.

Command Buttons and Events

You saw how CommandButton controls run code through event procedures such as Command1_Click.

Selection Controls

You explored ListBox, ComboBox, CheckBox, and OptionButton controls for user choices.

Graphics and Visual Controls

You learned how PictureBox, Image, and Shape controls can improve the visual interface of a VB6 application.

Best Practice

Use meaningful control names such as txtName, lblResult, and cmdCalculate. Clear names make your VB6 code easier to read, debug, and maintain.

Practice Exercises

Try these exercises to strengthen your understanding of VB6 controls:

Exercise 1: Caption Changer

Create a form with a command button that changes the form caption when clicked.

Exercise 2: Simple Addition Form

Use two text boxes, one command button, and one label to add two numbers and display the result.

Exercise 3: ListBox Menu

Add several programming topics to a ListBox using AddItem, then display the selected item in a label.

Exercise 4: OptionButton Color Selector

Create three option buttons named Red, Blue, and Green. When the user clicks a button, change the form background color.

Exercise 5: Picture Loader

Create a button that loads an image into a PictureBox using the LoadPicture function.

Next Lesson

Continue your VB6 journey with Lesson 4: Writing the Code.

Related Resources

Full VB6 Tutorial Index

Complete list of all VB6 lessons with descriptions.

Explore Tutorials

Visual Basic Examples

Practical VB6 code samples for real-world applications.

View Examples

Creating Applications in VB6

Review how a VB6 application is created before working with more controls.

Previous Lesson

Writing VB6 Code

Learn how to write cleaner code and event procedures in the next lesson.

Next Lesson

πŸš€ 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 β†’