Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDraw color gradients
Keywordscolor gradients, gradients
CategoriesGraphics
 
Darko Stanimirovic provides these two examples that draw color gradients. The idea is to draw lines or circles spaced 1 pixel apart with slightly different colors.

In the following code, BeginColor represents the red, green, and blue components of the gradient's starting color. Rlevel, Glevel, and Blevel are the differences between the starting and ending red, green, and blue components divided by the width of the form in pixels. Thus, for example, BeginColor.r + i * Rlevel gives the red component value for the ith pixel.

 
Dim tt As Long
MoveToEx picMain.hdc, 0, 0, Lppoint

'Begin gradient fill
For tt = 0 To pWidth
    picMain.ForeColor = RGB( _
        BeginColor.r + tt * Rlevel, _
        BeginColor.g + tt * Glevel, _
        BeginColor.b + tt * Blevel)
    LineTo picMain.hdc, tt, pheight

    MoveToEx picMain.hdc, tt, 0, tmp

Next tt
picMain.Refresh
 
This example uses API functions to draw but you could just as easily use Visual Basic's Line method.
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated