* VB-CODE (2)
Tip 84: Creating a Scrolling "Credits" Control
May 15, 1995
You can add visual appeal to your Visual Basic=AE applications by
including a routine that automatically scrolls text vertically within
a picture box. This article explains how you can add this
functionality to your programs.
Scrolling Text Vertically Within a Picture Box
The Windows=AE application programming interface (API) BitBlt function
can be used to copy a section of a Picture Box control to another
section of that same control. You must remember to set the ScaleMode
property of the Picture Box control to Pixel mode.
The example program below shows how to use the BitBlt function to
print scrolling text on a Picture Box control. A Timer control is
used to print a string of text on the Picture Box control at selected
1. Create a new project in Visual Basic. Form1 is created by default.
2. Add the following code to the General Declarations section of
Form1 (note that the Declare statement must be typed as a single
line of code):
Const SRCCOPY =3D &HCC0020
Const ShowText$ =3D "This line of text scrolls vertically."
Private Declare Function BitBlt Lib "GDI" (ByVal hDestDC As Integer,
ByVal X As Integer, ByVal Y As Integer, ByVal nWidth As Integer,
ByVal nHeight As Integer, ByVal hSrcDC As Integer,
ByVal XSrc As Integer, ByVal YSrc As Integer,
ByVal dwRop As Long) As Integer
3. Add a Picture Box control to Form1. Picture1 is created by
default. Set its ScaleMode property to 3-Pixel.
4. Add a Timer control to Form1. Timer1 is created by default. Set
its Interval property to 25.
5. Add the following code to the Timer event for Timer1 (note that
the Ret =3D line must be typed as a single line of code):
Private Sub Timer1_Timer()
Dim Ret As Integer
If (ShowIt% =3D 30) Then
Picture1.CurrentX =3D 0
Picture1.CurrentY =3D Picture1.ScaleHeight - 30
ShowIt% =3D 0
Ret =3D BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight - 1, Picture1.hDC, 0, 1, SRCCOPY)
ShowIt% =3D ShowIt% + 1
Run the program by pressing the F5 function key. After a short time,
the text "This line of text scrolls vertically." will be displayed in
the Picture Box control. Each time the Timer control reaches 25, the
line of text will be scrolled upward in the Picture Box control.
Tip 45: Using BitBlt to Display Bitmaps
"BITBLT: Tests the BitBlt Function." (Sample Code, Sample City,
Visual Basic Samples)
Knowledge Base Q71104. "How to Use Windows BitBlt Function in
Visual Basic Application."