Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a ransom note style message by drawing text using different fonts for each character in a RichTextBox in Visual Basic 6
DescriptionThis example shows how to make a ransom note style message by drawing text using different fonts for each character in a RichTextBox in Visual Basic 6.
Keywordsransom note, text, string, random fonts, random characters, Visual Basic 6, VB 6
CategoriesStrings, Puzzles and Games
 

The example Draw text using different fonts for each character explains how you can draw a string with each character drawn in a random font. This example does the same thing except it places the characters in a RichTextBox so you can copy and paste it into a document or email (assuming your email system can handle RTF text).

The program loops through each character in the string and calls PrintCharacter to draw each with a random font.

 
' Print this character in a random font.
Private Sub PrintCharacter(ByVal ch As String, ByVal rch As _
    RichTextBox)
    ' Add the character at the end of the RichTextBox.
    rch.SelStart = Len(rch.Text)
    rch.SelText = ch

    ' Select the new character.
    rch.SelLength = 1

    ' Pick a random font.
    rch.SelFontName = m_Fonts(Int(Rnd * m_Fonts.Count + 1))
    rch.SelBold = (Rnd * 1 < 0.5)
    rch.SelItalic = (Rnd * 1 < 0.5)
    'rch.SelStrikeThru = (Rnd * 1 < 0.1)
    'rch.SelUnderline = (Rnd * 1 < 0.1)
    rch.SelCharOffset = 100 - Rnd * 200
    rch.SelFontSize = MIN_SIZE + Rnd * (MAX_SIZE - MIN_SIZE)

    rch.SelColor = QBColor(Int(Rnd * 15))
End Sub
 
PrintCharacter adds a character to the end of the RichTextBox's text. It then selects that character and picks random font properties for it.
 
 
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated