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 sits horizontally but with a baseline that follows a curve
DescriptionThis example shows how to draw text that sits horizontally but with a baseline that follows a curve in Visual Basic 6.
Keywordstext, curve, wave, wavy
CategoriesGraphics
 
Subroutine DrawWavedText loops through the letters in a string. For each, it calculates the Y value of a Sine wave for the letter's X coordinate. It sets the drawing object's CurrentX and CurrentY properties and draws the letter. Optionally it also draws that piece of the curve so you can see the text follow it.
 
Private Sub DrawWavedText(ByVal obj As Object, ByVal txt As _
    String, ByVal x0 As Single, ByVal y0 As Single, _
    Optional ByVal draw_above As Boolean, Optional ByVal _
    draw_curve As Boolean = False)
Dim i As Integer
Dim ch As String
Dim y_offset As Single
Dim x1 As Single
Dim y1 As Single
Dim x2 As Single
Dim y2 As Single

    If draw_above Then
        y_offset = -obj.TextHeight("X")
    Else
        y_offset = 0
    End If

    x1 = x0
    y1 = F(x1) + y0
    x2 = x1
    y2 = y1
    For i = 1 To Len(txt)
        ' Draw the next character.
        obj.CurrentX = x2
        obj.CurrentY = y2 + y_offset
        ch = Mid$(txt, i, 1)
        obj.Print ch;

        ' Draw the line on the curve if desired.
        If draw_curve Then
            obj.Line (x1, y1)-(x2, y2)
        End If

        ' Move to the next point.
        x1 = x2
        y1 = y2
        x2 = x2 + obj.TextWidth(ch)
        y2 = F(x2) + y0
    Next i
End Sub

Private Function F(ByVal x As Single) As Single
    F = MAX * Sin(x / 250)
End Function
 
See also Print text that follows a curve.
 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated