You are on page 1of 12

Unit 4 – Controls

Discussed about Scroll Bar in Visual Basic 6.0.


 The Scrollbar is a commonly used control and enables the user to select a integer value
by positioning it at the desired location.
 Scrollbar represents a set of values.
 The min and max property represents the minimum value and maximum value.
 The value property represents its current value.
There are two types in Scrollbar ie.
1. Horizontal Scroll Bar (Used to display Horizontally)
2. Vertical Scroll Bar (Used to display Vertically)
The most important run-time property is Value, which always returns the relative position of the
indicator on the scroll bar. By default, the Min value corresponds to the leftmost or upper end of the
control.

Figure : Scroll Bar

Example Program : Changing Colors Using Scroll Bars

1
Coding:
Private Sub Form_Load()
Form1.WindowState = 2
Shape1.BackColor = &H8000000A
Shape1.Shape = 2
End Sub

Private Sub HScroll1_Change()


'HScroll1 for Red Value
Shape1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
'Lable is used to display the Current Value of Scroll Bar
Label1.Caption = HScroll1.Value
End Sub

Private Sub HScroll2_Change()


'HScroll2 for Green Value
Shape1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
'Lable is used to display the Current Value of Scroll Bar
Label2.Caption = HScroll2.Value
End Sub

Private Sub HScroll3_Change()


'HScroll3 for Blue Value
Shape1.BackColor = RGB(HScroll1.Value, HScroll2.Value, HScroll3.Value)
Label3.Caption = HScroll3.Value
End Sub

2
Discuss about DriveListBox, DirListBox, And FileListBox Controls In Visual Basic 6.
These Three Controls are used to work with the Computer File System.

Figure : DriveListBox, DirListBox, And FileListBox

1.Drive List Box control


 The Drive List Box control allows a user to select a Computer's Disk Drive at run-time.
 It displays the available Drives in a drop-down combo box.

Example:
Drive1.Drive
above command is used display Available Drivers of your computer system at run time.

Output:

Drive List Box Properties:


Drive Contains the name of the currently selected drive.

2.DirListBox
The DirListBox is a special list box that displays the Computer's disk directories and
subdirectories.

3
Example:
Dir1.Path
Above directory command is used to display e Computer's directories and subdirectories.
Directory List Box Properties:
Path Contains the current directory path.

Output:

3. FileListBox
FileListBox control displays all the files in a given directory.

File List Box Properties:


FileName Contains the currently selected file name.
Path Contains the current path directory.
Pattern Contains a string that determines which files will be displayed.

Example:
File1.Path
Above the command is used to display files of a Directory.

4
Output

Example Program : Display a File Using DriveListBox, DirListBox, FileListBox and OLE Controls
in VB.

Private Sub Dir1_Change()


File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()


Dir1.Path = Drive1.Drive
End Sub
Private Sub File1_Click()
Dim filePaths As String
Dim fileName As String
Dim FullPath As String
Dim temp As String
filePaths = File1.Path
fileName = File1.fileName
temp = filePaths & "\"
FullPath = temp & fileName
OLE1.OLETypeAllowed = acOLELinked
OLE1.SourceDoc = (Dir1.Path & File1.fileName)
OLE1.Action = acOLECreateLink
End Sub

5
Private Sub Form_Load()
Form1.WindowState = 2
End Sub

Form Design to Display a File Using DriveListBox, DirListBox, FileListBox and OLE Controls

Discuss about the Image Box Control in Visual Basic.


 An image box is used to place images or graphics information on a form.
 Image boxes are more suited for static situations ie. where no modifications will be
done to the displayed graphics.
 Image box graphics can be resized by using the Stretch property.
Image Box Properties:
Picture Establishes the graphics file to display in the image box.
Stretch If False, the image box resizes itself to fit the graphic. If True, the graphic resizes to fit
the control area.

6
It is used to display a graphics image from any of the following types of files:
 Bitmap (.bmp)
 GIF file
 JPEG file
Image Box Control Syntax to Display a File:
Image1.picture = LoadPicture( “Image Path Name”)
Image1.picture = LoadPicture( “D:\pictures\car.JPG”)
LoadPicture function is used to load the image in Image Box Control.

Discuss about Timer Control in Visual Basic 6.0.


 Timer Control is used to perform tasks at regular intervals.
 The timer tool does not appear on the form while the application is running.
 Timer tools work in the background, only being invoked at time intervals you specify.

Timer Properties:
 Timer1.Enabled =TRUE / FALSE
Above command is used to enable/disable the Timer Control
 Timer1.Interval =10
Above command is used to define Number of milliseconds between each
invocation of the Timer Event.

Figure: Time Control


Example for Timer Control Program:
Private Sub Command1_Click()
Timer1.Enabled = False
Label1.Caption = 0
Timer1.Enabled = True
End Sub

7
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub

Private Sub Command3_Click()


Timer1.Enabled = False
Label1.Caption = 0
End Sub

Private Sub Form_Load()


Timer1.Enabled = False
Form1.WindowState = 2
End Sub

Private Sub Timer1_Timer()


Label1.Caption = Label1.Caption + 0.01
End Sub

Output:

8
Discuss about the Picture Box Control in Visual Basic 6.0
 The Picture Box Control is used to display images on a form.
 It is best suited for dynamic environments - for example, when doing animation.

It is used to display a graphics image from any of the following types of files:
 Bitmap (.bmp)
 GIF file
 JPEG file

Image Box Control Syntax to Display a File:


Picture1.picture = LoadPicture( “Image Path Name”)
Picture1.picture = LoadPicture( “D:\pictures\car.JPG”)

Example Program : Animate a image using Picture Box Control & Timer in Visual Basic 6.0.
Coding:
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 100
End Sub

Private Sub Command2_Click()


Timer1.Interval = 0
End Sub

Private Sub Command3_Click()


Timer1.Interval = 0
End Sub

Private Sub Form_Load()


Form1.WindowState = 2
Timer1.Interval = 0
End Sub

Private Sub Timer1_Timer()


Frame1.Left = Frame1.Left + 100

9
If Frame1.Left > Me.Width Then
Frame1.Left = 0
End If
End Sub

Form Design

Discuss about the Shape Control in Visual Basic 6.0


 Shape Control is a Visual element that contains several predefined shapes.
 The shape tool can create circles, ovals, squares, rectangles, and rounded squares and
rectangles.
 The default shape is rectangle.
 Colors can be used and various fill patterns are available.

Shape Tool Properties:


Shape : It determines whether the shape is a square, rectangle, circle, or some other choice.
BackColor : It determines the background color of the shape
BorderWidth: It determines the width of the shape border line.
FillStyle: It determines the interior pattern of a shape.

10
Example Program : Write a Program to display different Shapes Using List Box Control.
Coding:
Private Sub Form_Load()
Form1.WindowState = 2
List1.AddItem "Rectangle"
List1.AddItem "Square"
List1.AddItem "Oval"
List1.AddItem "Circle"
List1.AddItem "Rounded Rectangle"
List1.AddItem "Rounded Square"
Shape1.BackColor = &H8000000A
Shape1.Shape = 2
End Sub

Private Sub List1_Click()


Shape1.BackColor = &H80C0FF
Select Case List1.ListIndex
Case 0
Shape1.Shape = 0
Case 1
Shape1.Shape = 1
Case 2
Shape1.Shape = 2
Case 3
Shape1.Shape = 3
Case 4
Shape1.Shape = 4
Case 5
Shape1.Shape = 5
End Select
End Sub

11
Form Design & Output:

12

You might also like