by Rob Dropkin and Imy (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Wed 24th March 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
RANDOM BG COLORS AND GREYSCALE COLORS!!!
API Declarations
Private intGreen As Integer
Private intBlue As Integer
Private intCount As Integer
Private intCountR As Integer
Private intCountG As Integer
Private intCountB As Integer
Option Explicit
'Create a frame with 2 option buttons(default names used in code) for color/greyscale option.
'Create a timer(default name) enabled = false and interval = 50.
'Create command button cmdPause.
'Create label lblCode to display the rgb values.
'Make sure on the label the backstyle property is transparent.
'************************************************
Public Sub Colors1()
If intCountR = 1 Then
intRed = intRed + (Rnd * 20 + 1)
If intRed > 255 Then
intRed = 255
intCountR = 2
End If
End If
If intCountR = 2 Then
intRed = intRed - (Rnd * 20 + 1)
If intRed < 0 Then
intRed = 0
intCountR = 1
End If
End If
If intCountG = 1 Then
intGreen = intGreen + (Rnd * 20 + 1)
If intGreen > 255 Then
intGreen = 255
intCountG = 2
End If
End If
If intCountG = 2 Then
intGreen = intGreen - (Rnd * 20 + 1)
If intGreen < 0 Then
intGreen = 0
intCountG = 1
End If
End If
If intCountB = 1 Then
intBlue = intBlue + (Rnd * 20 + 1)
If intBlue > 255 Then
intBlue = 255
intCountB = 2
End If
End If
If intCountB = 2 Then
intBlue = intBlue - (Rnd * 20 + 1)
If intBlue < 0 Then
intBlue = 0
intCountB = 1
End If
End If
End Sub
'-----------------------------------------------------
Public Sub Grey1()
If intCount = 1 Then
intRed = intRed + 10
intGreen = intGreen + 10
intBlue = intBlue + 10
If intRed > 255 Or intGreen > 255 Or intBlue > 255 Then
intRed = 255
intBlue = 255
intGreen = 255
intCount = 2
End If
End If
If intCount = 2 Then
intRed = intRed - 10
intGreen = intGreen - 10
intBlue = intBlue - 10
If intRed < 1 Or intGreen < 1 Or intBlue < 1 Then
intRed = 1
intBlue = 1
intGreen = 1
intCount = 1
End If
End If
End Sub
Private Sub cmdPause_Click()
Timer1.Enabled = False
Option1.Value = False
Option2.Value = False
End Sub
Private Sub Form_Load()
intRed = 1
intBlue = 1
intGreen = 1
intCount = 1
intCountR = 1
intCountG = 1
intCountB = 1
Timer1.Enabled = True
End Sub
Private Sub Option1_Click()
Timer1.Enabled = True
End Sub
Private Sub Option2_Click()
intRed = (intBlue + intGreen + intRed) / 3
intBlue = intRed
intGreen = intRed
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If Option1.Value = True Then
Call Colors1
ElseIf Option2.Value = True Then
Call Grey1
End If
frmColors.BackColor = RGB(intRed, intGreen, intBlue)
Frame1.BackColor = RGB(intRed, intGreen, intBlue)
Option1.BackColor = RGB(intRed, intGreen, intBlue)
Option2.BackColor = RGB(intRed, intGreen, intBlue)
lblCode.ForeColor = RGB(255 - intRed, 255 - intGreen, 255 - intBlue)
lblCode.Caption = intRed & " , " & intGreen & " , " & intBlue
Frame1.ForeColor = RGB(255 - intRed, 255 - intGreen, 255 - intBlue)
Option1.ForeColor = RGB(255 - intRed, 255 - intGreen, 255 - intBlue)
Option2.ForeColor = RGB(255 - intRed, 255 - intGreen, 255 - intBlue)
End Sub