borderAndreaVB free resources for Visual Basic developersborder

AndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincani
:: Create a Form with a Faded Background

Author  

Andrea Tincani

Language  

VB5, VB6

Operating Systems  

Windows 95, 98 and NT
API Declarations

Option Explicit

' Data type used by FillRect
Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
End Type

' API Functions used to create solid brush and draw brush on form
Public Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
Public Declare Function FillRect Lib "user32.dll" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Public Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long

Module

Public Sub FadeForm(frm As Form, colStart As Long, colEnd As Long)
    Dim red As Single
    Dim green As Single
    Dim blue As Single
    Dim redStep As Single
    Dim greenStep As Single
    Dim blueStep As Single
    Dim StepInterval As Single
    Dim X As Long
    Dim ret As Long
    Dim OldMode As Long
    Dim FillArea As RECT
    Dim rTop As Single
    Dim hBrush As Long

   
' retrive the old scale mode of the form
    OldMode = frm.ScaleMode
   
' set the Scale Mode of the form to Pixels
    frm.ScaleMode = vbPixels
   
' calculate the vertical step and the colors step
    StepInterval = frm.ScaleHeight / 64
    blue = (colStart \ &H10000) And &HFF
    blueStep = (blue - ((colEnd \ &H10000) And &HFF)) / 64
    green = (colStart \ &H100) And &HFF
    greenStep = (green - ((colEnd \ &H100) And &HFF)) / 64
    red = (colStart And &HFF)
    redStep = (red - (colEnd And &HFF)) / 64
    rTop = 0
    FillArea.Left = 0
    FillArea.Right = frm.ScaleWidth
    FillArea.Top = 0
    FillArea.Bottom = StepInterval
   
' paint the form with a gradient brush
    For X = 1 To 64
        hBrush = CreateSolidBrush(RGB(red, green, blue))
        ret = FillRect(frm.hdc, FillArea, hBrush)
        ret = DeleteObject(hBrush)
        red = red - redStep
        green = green - greenStep
        blue = blue - blueStep
        rTop = rTop + StepInterval
        FillArea.Top = rTop
        FillArea.Bottom = rTop + StepInterval
    Next
End Sub

Usage

' Create a Form and add the following code in the Paint and Resize events
Private Sub Form_Paint()
   
' Paint the Form's Background starting with Blue on top and fading to black
    FadeForm Me, RGB(0, 0, 255), RGB(0, 0, 0)
End Sub

Private Sub Form_Resize()
   
' Do the same on the resize event
    FadeForm Me, RGB(0, 0, 255), RGB(0, 0, 0)
End Sub

:: Navigation

Home

Form Tips

Previous Tip

Next Tip

:: Search this site
Google
:: Related Topics
icon 19-03-2008 Re: Loops pls help by stickleprojects
icon 18-03-2008 VB code generation TSQL scripts for SQL2k by stickleprojects
icon 28-02-2008 Re: How to create a common menu for whole proj? #1 by Bharathi
icon 21-02-2008 Database searching by Muthu
icon 20-02-2008 Printing using with "Printer" object by Muthu
:: Sponsored Links



Partners: Il portale per lui e lei | Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder