increase RGB in gradient

sambase
01-06-2005, 12:53 PM
i was playing around with some code and came up with this..


Private Sub Form_Load()



For i = 0 To 8
With Text1(i)
.Text = .Index
.BackColor = RGB(.Index * 15, .Index * 20, .Index * 25)
.ForeColor = RGB(255, 255, 255)
.Width = 3000
.Height = 50
.Top = Val(.Index * 190)
.Left = 0
With Form1
.Width = 3000
.Height = 3000
End With
End With

Next i


End Sub


i have 9 text boxes on a form which the backcolor for each creates a gradient style look on the form. i would like to know how to increase the RGB for each text box on an event. so eventually the gradient will change colour.

thanks.

sam

noi_max
01-06-2005, 01:35 PM
I did a quick search and found a Long to RGB converter that Iceplug posted:
http://www.xtremevbtalk.com/showthread.php?t=36844

This is easier to post than to explain. I used a User Defined Type to hold the RGB values and passed them to a function I made to do the conversion. (with help form Iceplug's post of course!)

Put a timer on your form and modify your code a little like this:

Option Explicit

Private Type mRGB
R As Byte
G As Byte
B As Byte
End Type

Private tRGB As mRGB

Private Function GetRGB(lCOlor As Long) As mRGB

GetRGB.R = lCOlor Mod 256
GetRGB.G = (lCOlor \ 256) Mod 256
GetRGB.B = (lCOlor \ 65536)

End Function

Private Sub Form_Load()

Dim i&

For i = 0 To Text1.UBound

With Text1(i)
.Text = .Index
.BackColor = RGB(.Index * 15, .Index * 20, .Index * 25)
.ForeColor = RGB(255, 255, 255)
.Width = 3000
.Height = 50
.Top = Val(.Index * 360)
.Left = 0

With Form1
.Width = 3000
.Height = 3000
End With

End With

Next i

'Start timer to fade colors
Timer1.Interval = 500
Timer1.Enabled = True

End Sub

Private Sub Timer1_Timer()

Dim lOldColor&, i&

For i = 0 To Text1.UBound

'Get original backcolor of textbox
lOldColor = Text1(i).BackColor

'Use function to get the RGB values
tRGB = GetRGB(lOldColor)

'Increase red
If tRGB.R < 245 Then
tRGB.R = tRGB.R + 10
End If

'Change the backcolor of the textbox
Text1(i).BackColor = RGB(tRGB.R, tRGB.G, tRGB.B)

Next i

End Sub


Try experimenting with increasing different color amounts.

:cool:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum