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 lines of text with random colors
DescriptionThis example shows how to draw lines of text with random colors in Visual Basic 6. The program loads a text file, uses Split to break it into lines, and then draws each line on a PictureBox in a different color.
Keywordscolor, text, random colors
CategoriesGraphics, Puzzles and Games
 
Thanks to Dipak Auddy.

Subroutine readFile loads a text file and uses Split to break it into lines. Subroutine showFile draws the lines of text on a PictureBox using random colors.

 
'Read file and store into array
Private Sub readFile()

Dim fData As String

    'read
    Open fName For Binary Access Read As #1
    fData = StrConv(InputB$(LOF(1), 1), vbUnicode)
    Close #1
    'Load FileData
    aray = Split(fData, vbCrLf)
    VScroll1.Value = 0
    HScroll1.Value = 0
    showFile

End Sub

'Draw FileData
Private Sub showFile()

Dim i As Integer

    picCanvas.Cls
    WandH
    '    HScroll1.Max = picCanvas.Width
    '    VScroll1.Max = picCanvas.Height
    On Error GoTo ER
    picCanvas.CurrentY = 100
    For i = 0 To UBound(aray)
        '<:-) Auto-inserted With End...With Structure
        With picCanvas
            'picCanvas.ForeColor = QBColor(Rnd * 15)
            .ForeColor = ranColor()
            .CurrentX = 100
            picCanvas.Print aray(i)
        End With 'picCanvas
    Next '  I
    StatusBar1.Panels(1).Text = "Ready "
    Me.MousePointer = vbDefault
    Form_Resize
ER:

End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated