Common Properties in VB6

In this lesson, you'll learn about the common properties used in VB6.

BackColor and ForeColor

The BackColor property sets the background color of an object while the ForeColor property changes the foreground color used to display text.

You can set these properties either from Properties Window or you may wish to set in run-time.

When you click on command1 button, the code in the Click event procedure is executed.
Private Sub cmdChangeColor_Click()
    Label1.BackColor = vbRed
    Label1.ForeColor = vbBlue
End Sub

On execution, the background color of the label will be red and label's text color will be blue.

'vbRed' and 'vbBlue' are the color constants.

Another example:
Private Sub cmdChangeColor_Click()                  
    Label1.BackColor = vbRed                      
    Label1.ForeColor = vbBlue                     
    Form1.BackColor = vbGreen                     
    Text1.BackColor = vbBlack                     
    Text1.ForeColor = vbYellow                    
    Frame1.BackColor = vbWhite                    
End Sub

The color can also be expressed in hexadecimal code.

Private Sub cmdChangeColor_Click()
    Label1.BackColor = &HFF&
    Label1.ForeColor = &HC00000
End Sub

In this case, you have to copy the hexadecimal code from Properties Window. 


You can set the font property from the Properties Window. See the below example to set property in run time.

Private Sub cmdChangeFont_Click()
    Text1.FontSize = 16
    Text1.FontBold = True
    Text1.FontItalic = True
    Text1.Font = "Tahoma"
End Sub

The above block of code can be written in the following way too.
Private Sub cmdChangeFont_Click()
    Text1.Font.Size = 16
    Text1.Font.Bold = True
    Text1.Font.Italic = True
    Text1.Font.Name = "Tahoma"
End Sub



It sets the text displayed in the object's title bar or on the object.

Private Sub cmdSetTitle_Click()
    Form1.Caption = "New Program"
    Label1.Caption = "Hello"
    Frame1.Caption = "New frame"
End Sub 
'Caption' property of form sets the form's title text. The text to be displayed on label is set.


It sets the text in a TextBox.

Text1.Text = "New program"

Here the text string is assigned to Text1.Text.

The above program is explained in the following page:

The Left, Top, Width and Height properties

1. The Left Property sets the distance between the internal left edge of an object and the left edge of its container.
2. The Top Property sets the distance between the internal top edge of an object and the top edge of its container.
3. The Width Property sets the width of an object.
4. The Height Property sets the height of an object.

Private Sub cmdChange_Click()
     Form1.Left = 12000
     Form1.Top = 7000
     Form1.Height = 10000
     Form1.Width = 12000
End Sub


Moves an object into another container. You don't see it in the Properties Window, it is a run-time only property.
In this case, you need to start with the 'Set' keyword.

Set Command1.Container = Frame1

The command1 control will be moved into frame1.


Determines whether an object is visible or hidden.

Label1.Visible = False


Determines whether an object can respond to user generated events.


MousePointer and MouseIcon

The MousePointer property sets the type of mouse pointer over an object. The values of MousePointer property are
0- Default
1- Arrow
2- Cross
3- I-Beam
4- Icon
5- Size  etc.
The MouseIcon property sets a custom mouse icon from your files.

The above program is explained in the following page:

TabIndex and TabStop

The TabStop property indicates whether the user can use the TAB key to give the focus to an object. You can give focus to the objects pressing the TAB key in the daily use software applications. 
The TabIndex property sets the tab order of an object.

Command3.TabIndex = 0
Command2.TabIndex = 1
Command1.TabIndex = 2

When you press the TAB key, the focus will be given on Command3 first, then on Command2 and at last on Command1.


Determines whether an object is movable.


Determines whether an object e.g TextBox can be edited.


Stores any extra data for your program that is used in the code.

Control Box

Indicates whether a control-menu box is displayed on the form at run time. If this property is set to False, the Close Button, Minimize Button and Maximize Button are not shown on the form.


Determines whether the form appears in the windows taskbar.


Specifies the position of the form when it first appears.


Sets the icon displayed when the form is minimized at run time.