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
 
 
 
 
 
TitleMake selected text blink in a PictureBox
Keywordsblink, text, PictureBox, color, flash
CategoriesControls, Graphics
 
Use a Timer. When the Timer fires, redraw the text using the new color.

This example stores the position of text it should make blink in the Xpos amd Ypos collections. It stores the text values in the BlinkText collection.

Subroutine PrintLine breaks its text into pieces separated by a target string. It then displays each of the pieces and the target strings between them. Each time it displays a target, it stores the target's position and value.

 
Private Xpos As New Collection
Private Ypos As New Collection
Private BlinkText As New Collection

' Print a line, saving the position of the text
' target for blinking.
Private Sub PrintLine(txt As String, target As String)
Dim pieces As Variant
Dim i As Integer

    ' Break the text into pieces.
    pieces = Split(txt, target)

    ' Display the first piece.
    Picture1.Print pieces(0);

    ' Display the rest of the pieces.
    For i = LBound(pieces) + 1 To UBound(pieces)
        ' Save the target here.
        Xpos.Add Picture1.CurrentX
        Ypos.Add Picture1.CurrentY
        BlinkText.Add target

        ' Display the target.
        Picture1.Print target;

        ' Display the next piece.
        Picture1.Print pieces(i);
    Next i

    Picture1.Print
End Sub
 
The Form_Load event handler calls PrintLine to display several lines of text. It tells PrintLine to save the locations of the string "Active."
 
Private Sub Form_Load()
    Picture1.Font.bold = True
    PrintLine "Name                Date of Birth           " & _
        "Status", "XXXXX"
    Picture1.Font.bold = False
    PrintLine "Jane Smith          01/01/1961              " & _
        "Active", "Active"
    PrintLine "Rod Stephens        02/02/1962              " & _
        "Inactive", "Active"
    PrintLine "Julia Keeley        03/03/1963              " & _
        "Active", "Active"
    PrintLine "Micky Johnson       04/04/1964              " & _
        "Inactive", "Active"
    PrintLine "Ben Pierce          05/05/1965              " & _
        "Inactive", "Active"
    PrintLine "Linda Roberts       06/06/1966              " & _
        "Active", "Active"
End Sub
 
When the Timer event fires, the program redraws the saved text in a new color.
 
' Switch the color of the saved targets.
Private Sub tmrBlink_Timer()
Dim i As Integer

    If Picture1.ForeColor = vbRed Then
        Picture1.ForeColor = vbBlack
    Else
        Picture1.ForeColor = vbRed
    End If

    For i = 1 To Xpos.Count
        Picture1.CurrentX = Xpos(i)
        Picture1.CurrentY = Ypos(i)
        Picture1.Print BlinkText(i)
    Next i
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated