Visual Basic Tip: 03/11/96


Smooth Scroll Graphics and Text.

Smooth scroll graphics and text up a window.  This effect is similar
to the closing credits of a movie.  The example shows the basics of
scrolling text up a form.  It can easily be modified to scroll graphics
on a form or other controls (ex: a picture box).

Create a new project.  Add picture box to the form.  Rename the picture
box to P1.  Add a timer to the form.  Add the code listed below to the
form.


'declares
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

Dim thetop As Long
Dim p1hgt  As Long
Dim p1wid  As Long
Dim theleft As Long


Sub centerIT (C As Control, Txt As String)
    C.CurrentX = (C.ScaleWidth - C.TextWidth(Txt)) / 2
    C.Print Txt
End Sub


Sub Form_Load ()
 p1.autoredraw = true
 p1.visible = false
 p1.FontSize = 12
 p1.ForeColor = &HFF0000
 p1.BackColor = BackColor
 p1.ScaleMode = 3

 centerIT p1, "Hi!!!"
 centerIT p1, "Scroll Test..."

 ScaleMode = 3
 theleft = (ScaleWidth - p1.TextWidth("Scroll Test...")) / 2

 thetop = ScaleHeight
 p1hgt = p1.ScaleHeight
 p1wid = p1.ScaleWidth

 timer1.Enabled = True
 timer1.Interval = 10
End Sub


Sub Timer1_Timer ()
 X% = BitBlt(hDC, theleft, thetop, p1wid, p1hgt, p1.hDC, 0, 0, &HCC0020)
 thetop = thetop - 1
 If thetop < -p1hgt Then
  Timer1.Enabled = False
  Txt$ = "Finished With Scrolling"
  CurrentY = ScaleHeight / 2
  CurrentX = (ScaleWidth - TextWidth(Txt$)) / 2
  Print Txt$
 End If
End Sub

Return to Phil's Web Page

Created by: Philip