|
|
Title | Draw text using different fonts for each character |
Description | This 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. |
Keywords | text, font, random font |
Categories | Graphics, 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
|
|
|
|
|
|