Visual Basic Tip: 10/23/95


How to Fade a Form Background from Blue to Black.
This effect is usually used by Setup programs.  Also try other color
combinations for unique effects (see the comment line in Fade subroutine).


' Declarations

Type Rect
    Left As Integer
    Top As Integer
    Right As Integer
    Bottom As Integer
End Type

Declare Function CreateSolidBrush Lib "GDI" (ByVal crColor As Long) As Integer
Declare Function FillRect Lib "User" (ByVal hDC As Integer, lpRect As Rect, ByVal hBrush As Integer) As Integer
Declare Function DeleteObject Lib "GDI" (ByVal hObject As Integer) As Integer


' Module (BAS) subroutine Fade
'  Call from form_paint, also set AutoRedraw = False
'  Routine can also be placed in the form_paint event

Sub Fade (TheForm As Form)
    Dim Blue%, hBrush%, OldMode%, RetVal%, StepSize%, X%
    Dim FillArea As Rect
    OldMode% = TheForm.ScaleMode
    TheForm.ScaleMode = 3               'Pixel
    StepSize% = 1 + TheForm.ScaleHeight \ 80
    Blue% = 255
    FillArea.Left = 0
    FillArea.Right = TheForm.ScaleWidth
    FillArea.Top = 0
    FillArea.Bottom = StepSize%
    Blue = 255
    For X% = 1 To 80
      hBrush% = CreateSolidBrush(RGB(0, 0, Blue%))
        ' try  RGB(0, 255, Blue%)  and other combinations!
      RetVal% = FillRect(TheForm.hDC, FillArea, hBrush%)
      RetVal% = DeleteObject(hBrush%)
      Blue% = Blue% - 4
      If Blue% < 0 Then Blue% = 0
      FillArea.Top = FillArea.Bottom
      FillArea.Bottom = FillArea.Bottom + StepSize%
    Next
    TheForm.ScaleMode = OldMode%
End Sub
Return to Phil's Web Page

Created by: Philip