Smooth scrolling marquee text (without API)
With this code you can scroll text smoothly in any direction without needing any API calls. All you need is a PictureBox control, a Label control, and a timer. The code is fully commented and has examples for scrolling in the four main directions.
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
Option Explicit
Private TheX as Long
Private TheY as Long
' I have included commented lines to scroll in any of the four main directions.
' You can uncomment the appropriate lines for your needs.
' If you uncomment both the left to right and bottom to top, for example,
' you get diagonal scrolling.
' I found that a timer interval of 50 milliseconds works well in most cases.
' Windows 95/98 machines don't get any faster from that point but NT machines do.
' Playing with the Timer's interval property as well as adjusting the number of
' pixels to step by will eventually satisfy your needs.
Private Sub Form_Load()
lblText.Caption = "Insert your credits here..." ' Set the text to be shown
' Use this line of code if you want to scroll right to left
TheX = pbScrollBox.ScaleWidth ' Set the starting point (off the right edge)
' Use this line of code if you want to scroll left to right
' TheX = 0 - lblText.Width ' Set the starting point (off the left edge)
' Use this line of code if you want to scroll bottom to top
' TheY = pbScrollBox.ScaleHeight ' Set the starting point (off the bottom edge)
' Use this line of code if you want to scroll top to bottom
' TheY = 0 - lblText.Height ' Set the starting point (off the top edge)
End Sub
Private Sub tmrScroll_Timer()
pbScrollBox.Cls ' so we don't get text trails
' Scroll from right to left
If TheX <= 0 - lblText.Width Then
TheX = pbScrollBox.ScaleWidth
Else
TheX = TheX - 1 ' larger number means faster scrolling
End If
' uncomment the following lines to scroll from left to right
' If TheX >= pbScrollBox.ScaleWidth Then
' TheX = 0 - lblText.Width
' Else
' TheX = TheX + 1
' End If
' uncomment the following lines to scroll from bottom to top
' If TheY <= 0 - lblText.Height Then
' TheY = pbScrollBox.ScaleHeight
' Else
' TheY = TheY - 1
' End If
' uncomment the following lines to scroll from top to bottom
' If TheY >= pbScrollBox.ScaleHeight Then
' TheY = 0 - lblText.Height
' Else
' TheY = TheY + 1
' End If
' set the text position and print the text
pbScrollBox.CurrentX = TheX
pbScrollBox.CurrentY = TheY
pbScrollBox.Print lblText.Caption
End Sub
Original Comments (3)
Recovered from Wayback Machine