VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Algorithm to fade an object from one color to another. Any type of control that has a BackColor pro

by Jon Mooty AKA YoungBuck (5 Submissions)
Category: Graphics
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Sat 13th January 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Algorithm to fade an object from one color to another. Any type of control that has a BackColor property can be used.

Rate Algorithm to fade an object from one color to another. Any type of control that has a BackColor pro



'*****************
'*****************
'~~~~~~~~~~~~~~~~~
' IN A .BAS MODULE
'~~~~~~~~~~~~~~~~~
'*****************
'*****************


Option Explicit

Private Type RGBColor
    R As Long
    G As Long
    B  As Long
 End Type

Public Sub FadeForm(pCtl As Object, pStartCol As Long, pEndCol As Long, pLoopCt As Long)
 Dim rgbS As RGBColor
 Dim rgbE As RGBColor
 Dim iRChg As Single, iGChg As Single, iBChg As Single
 Dim lCurColor As Long
 Dim iCt As Integer
 
 ' Retrieve the individual red, green, and blue values for the start color
 rgbS = IndColors(pStartCol)
 
 ' Retrieve the individual red, green, and blue values for the start color
 rgbE = IndColors(pEndCol)
 
 ' Get the amount to change the colors during the loop
 iRChg = (rgbE.R - rgbS.R) / pLoopCt
 iGChg = (rgbE.G - rgbS.G) / pLoopCt
 iBChg = (rgbE.B - rgbS.B) / pLoopCt
 
 For iCt = 1 To pLoopCt
    
    'get the value of the current color
    lCurColor = RGB(rgbS.R + iRChg * iCt, rgbS.G + iGChg * iCt, rgbS.B + iBChg * iCt)
    
    'display the  current color of the form
    pCtl.BackColor = lCurColor
    
    'allow other processes to execute
    DoEvents
    
 Next iCt
 
End Sub

Private Function IndColors(pCol As Long) As RGBColor

With IndColors

    .B = pCol \ 65536
    .G = (pCol - .B * 65536) \ 256
    .R = pCol - .B * 65536 - .G * 256
    
End With

End Function

'************
'**********
'~~~~~~~~~~
' IN A FORM
'~~~~~~~~~~
'**********
'**********

Private Sub Form_Load()
    
    Me.Show
    
    ' Fade a form from Blue to Green, run the coloring loop 10000 times
    ' To change the speed of the fading, then just simply adjust the pLoopCt parameter _
      the lower the number the faster the fading effect will occur
    FadeForm Me, vbBlue, vbGreen, 10000
    
End Sub

Download this snippet    Add to My Saved Code

Algorithm to fade an object from one color to another. Any type of control that has a BackColor pro Comments

No comments have been posted about Algorithm to fade an object from one color to another. Any type of control that has a BackColor pro. Why not be the first to post a comment about Algorithm to fade an object from one color to another. Any type of control that has a BackColor pro.

Post your comment

Subject:
Message:
0/1000 characters