Scrolling Colours

Visual Basic 5

This program uses Horizontal Scroll Bars and variables to create a colour palette.

Create a Form with the following objects:

3 Horizontal Scroll Bars
4 Text Boxes
3 Labels

Size and arrange the objects as shown.



Set the "max" property for each scroll bar to 255. This ensures that the maximum value for each scroll bar will not exceed 255.
(F4 displays property box)

Change the label captions to Red, Green and Blue.

The variables r, g and b represent the colour numbers for red, green and blue.
Declare these variables under "general" in the code window. (Dim r as Integer, etc.)

Here is the code for this program:


Dim r As Integer
Dim g As Integer
Dim b As Integer

Private Sub HScroll1_Change()

r = HScroll1.Value
Text2.Text = r
Text1.BackColor = RGB(r, g, b)

End Sub

Private Sub HScroll2_Change()

g = HScroll2.Value
Text3.Text = g
Text1.BackColor = RGB(r, g, b)

End Sub

Private Sub HScroll3_Change()

b = HScroll3.Value
Text4.Text = b
Text1.BackColor = RGB(r, g, b)

End Sub


"Start"


Return