devxlogo

Fading Colors

Fading Colors

Use this as a fast way to paint the background of any form witha really cool “fading” color (lighter at top to darkerat 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 = SaveRedrawEnd Sub

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

 FadeForm Me, False, False, True
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist