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 text that shades letter by letter from one color to another
Keywordstext, shade, color gradient
CategoriesGraphics
 

Calculate how much the color must change between letters. Note that all color calculations use Singles rather than Integers to prevent rounding errors.

Loop through the string's characters updating the color and drawing each letter.

 
' Draw the string with each character a different
' color shading from RGB(start_r, start_g, start_b) to
' RGB(end_r, end_g, end_b).
Private Sub ShadeString(ByVal canvas As Object, ByVal _
    start_x As Single, ByVal start_y As Single, ByVal _
    start_r As Integer, ByVal start_g As Integer, ByVal _
    start_b As Integer, ByVal end_r As Integer, ByVal end_g _
    As Integer, ByVal end_b As Integer, ByVal TXT As String)
Dim r As Single
Dim g As Single
Dim b As Single
Dim dr As Single
Dim dg As Single
Dim db As Single
Dim txt_len As Integer
Dim i As Integer

    txt_len = Len(TXT)
    dr = (end_r - start_r) / (txt_len - 1)
    dg = (end_g - start_g) / (txt_len - 1)
    db = (end_b - start_b) / (txt_len - 1)
    r = start_r
    g = start_g
    b = start_b
    canvas.CurrentX = start_x
    canvas.CurrentY = start_y
    For i = 1 To txt_len
        canvas.ForeColor = RGB(r, g, b)
        canvas.Print Mid$(TXT, i, 1);
        r = r + dr
        g = g + dg
        b = b + db
    Next i
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated