Home
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
 
 
 
 
TitleShade objects with a color gradient
Keywordsshade, gradient, color gradient
CategoriesGraphics
 
Either set the object's AutoRedraw property to True, or repeat the process in the object's Paint event handler.

Temporarily set the object's ScaleMode property to vbPixels so you can easily draw each pixel exactly once. Then use a loop to draw lines in different colors starting at the left edge of the object and moving to the right by one pixel each time.

 
' Shade the object from left to right.
Private Sub ShadeObject(ByVal pic As Object, _
  ByVal r1 As Byte, ByVal g1 As Byte, ByVal b1 As Byte, _
  ByVal r2 As Byte, ByVal g2 As Byte, ByVal b2 As Byte)
Dim old_scalemode As Integer
Dim wid As Integer
Dim hgt As Integer
Dim i As Integer
Dim dr As Single
Dim dg As Single
Dim db As Single

    old_scalemode = pic.ScaleMode
    pic.AutoRedraw = True
    pic.ScaleMode = vbPixels
    wid = pic.ScaleWidth
    hgt = pic.ScaleHeight

    dr = (CSng(r2) - r1) / wid
    dg = (CSng(g2) - g1) / wid
    db = (CSng(b2) - b1) / wid

    For i = 1 To wid
        pic.Line (i, 0)-Step(0, hgt), _
            RGB(r1 + i * dr, g1 + i * dg, b1 + i * db)
    Next i

    pic.ScaleMode = old_scalemode
End Sub
 
 
Copyright © 1997-2001 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated