Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Aug 6, 1997

Fading Colors

Use this as a fast way to paint the background of any form with a really cool "fading" color (lighter at top to darker at bottom). To specify base color, pass True/False for Red, Green, and Blue. Use combinations to fade blue, red, green, yellow, purple, gray, and so on:

 
Sub FadeForm (frm As Form, Red%, _
         Green%, Blue%)
         Dim SaveScale%, SaveStyle%, _
                SaveRedraw%
         Dim i&, j&, x&, y&, pixels%

         ' Save current settings.
         SaveScale = frm.ScaleMode
         SaveStyle = frm.DrawStyle
        SaveRedraw = frm.AutoRedraw

         ' Paint screen.
         frm.ScaleMode = 3
         pixels = Screen.Height / _
                Screen.TwipsPerPixelY
         x = pixels / 64# + .5
         frm.DrawStyle = 5
         frm.AutoRedraw = True
         For j = 0 To pixels Step x
                y = 240 - 245 * j \ pixels
                'can tweak this to preference.
                If y < 0 Then y = 0
                'just in case.
                frm.Line (-2, j - 2)- _
                        (Screen.Width + 2, j + _
                        x + 3), RGB(-Red * y, -Green _
                                * y, -Blue * y), BF
         Next j

         ' Reset to previous settings.
         frm.ScaleMode = SaveScale
         frm.DrawStyle = SaveStyle
         frm.AutoRedraw = SaveRedraw
End Sub




For blue fading, just put this in the Form_Load procedure:

 
FadeForm Me, False, False, True



Timothy L.
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap