VB and VBA Users Source Code: Creating a faded background on a form
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Creating a faded background on a form
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Thursday, August 07, 2003
Hits:
1722
Category:
Windows Forms/GUI/Controls/Graphics
Article:
The code below fades (washes) the background of a form with a specified color range. 'Purpose : Fades the backcolor of a form (useful for installation screens/wizards etc). 'Inputs : oForm The form to fade the backcolor on. ' [lBaseColor] The base color to use in the form fade. ' [lFadeColor] The color to fade the base color to. 'Outputs : N/A 'Author : Andrew Baker 'Date : 03/03/2003 'Example : FormFadeBackColor Me, vbBlue, vbGreen ' FormFadeBackColor Me, vbRed, vbGreen 'Revisions : Update supplied by K.Khan (removal of step parameter) Sub FormFadeBackColor(oForm As Form, Optional lStartColor As Long = vbBlack, Optional lEndColor As Long = vbBlue) Dim lRedStart As Long, lGreenStart As Long, lBlueStart As Long Dim lRedEnd As Long, lGreenEnd As Long, lBlueEnd As Long Dim fRedStep As Double, fGreenStep As Double, fBlueStep As Double Dim lStep As Long On Error GoTo ErrFailed oForm.AutoRedraw = True oForm.DrawStyle = vbInsideSolid oForm.DrawMode = vbCopyPen oForm.DrawWidth = 2 oForm.ScaleMode = vbPixels lRedStart = lStartColor And vbRed lGreenStart = (lStartColor And vbGreen) / (vbRed + 1) lBlueStart = (lStartColor And vbBlue) / (vbGreen + 1) lRedEnd = lEndColor And vbRed lGreenEnd = (lEndColor And vbGreen) / (vbRed + 1) lBlueEnd = (lEndColor And vbBlue) / (vbGreen + 1) fRedStep = (lRedEnd - lRedStart) / oForm.ScaleHeight fGreenStep = (lGreenEnd - lGreenStart) / oForm.ScaleHeight fBlueStep = (lBlueEnd - lBlueStart) / oForm.ScaleHeight For lStep = 0 To oForm.ScaleHeight oForm.Line (oForm.ScaleLeft, oForm.ScaleTop + lStep)-(oForm.ScaleLeft + oForm.ScaleWidth, oForm.ScaleTop + lStep), RGB(lRedStart + lStep * fRedStep, lGreenStart + lStep * fGreenStep, lBlueStart + lStep * fBlueStep), BF Next Exit Sub ErrFailed: Debug.Print err.description Debug.Assert False End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder