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 using different fonts for each character
DescriptionThis example shows how to draw text using different fonts for each character in Visual Basic 6. For each character, the program picks a random font, size, boldness, and other properties.
Keywordstext, font, random font
CategoriesGraphics, Puzzles and Games
 
When the user clicks Go, the program calls subroutine PrintCharacter for each character in the text.

PrintCharacter picks random font characteristics and then draws the character. The semi-colon after the character makes the control not start a new line.

After printing the character, the routine examines CurrentX to see if it should start a new line before drawing the next character.

 
Private Sub cmdGo_Click()
Dim txt As String
Dim i As Integer

    Me.Cls
    Me.CurrentX = 0
    Me.CurrentY = cmdGo.Top + cmdGo.Height + 60
    txt = txtText.Text

    For i = 1 To Len(txt)
        PrintCharacter Mid$(txt, i, 1)
    Next i
End Sub

' Print this character in a random font.
Private Sub PrintCharacter(ByVal ch As String)
    ' Pick a random font.
    Me.FontName = m_Fonts(Int(Rnd * m_Fonts.Count + 1))
    Me.FontBold = (Rnd * 1 < 0.5)
    Me.FontItalic = (Rnd * 1 < 0.5)
    'Me.FontStrikethru = (Rnd * 1 < 0.1)
    'Me.FontUnderline = (Rnd * 1 < 0.1)
    Me.FontSize = MIN_SIZE + Rnd * (MAX_SIZE - MIN_SIZE)
    Me.ForeColor = QBColor(Int(Rnd * 15))

    ' Draw the character.
    Me.Print ch;

    ' See if we need to move to the next line.
    If Me.CurrentX + 240 > Me.ScaleWidth Then
        Me.CurrentY = Me.CurrentY + m_LineHeight
        Me.CurrentX = 0
    End If
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated