I would like some help to create a text scroll in the background of a form. I want to have it constanly loop without getting trapped in a traditional loop where the users computer gets trapped in an endless loop. Any ideas?
Printable View
I would like some help to create a text scroll in the background of a form. I want to have it constanly loop without getting trapped in a traditional loop where the users computer gets trapped in an endless loop. Any ideas?
Use a timer control.
Example:
Put a Timer and a Picturebox with a Label inside it on a window.
Set Label1's caption to "Example Text Scroller for hlieu"
Set Timer1.Interval = 200
This will not cause an endless loopCode:Private Sub Timer1_Timer()
Label1.Left = Label1.Left - 105
If Label1.Left < (Label1.Width * -1) then Label1.Left = Picture1.Width
End Sub
Here's another way, without using a picture box.
Create a form, strech a label across it and keep the default name, Label1. Make sure you change the Alignment property to "1 - Right Justify" to scroll from right to left. Add a timer and set the interval to 50 to start with (this will control the speed of scrolling). Again, keep the default name Timer1.
Now paste this code into the form's code window and run the project:
If you want to stop the scrolling, set Timer1.Interval = 0 and Label1.Caption = "".Code:Option Explicit
Private sMsg As String 'Holds the scrolling message text
Private nStartPos As Integer 'Counter
Const nTextDisplayLen As Integer = 50 'Width of text to display
Private Sub Form_Load()
'Creates a message to scroll
sMsg = "Hello, how are you today? "
sMsg = sMsg & "I am fine. "
sMsg = sMsg & "Nice weather we're having. "
sMsg = sMsg & "Did you catch the game last night? "
End Sub
Private Sub Timer1_Timer()
nStartPos = nStartPos + 1
If nStartPos = Len(sMsg) Then
nStartPos = 1
End If
Label1 = right$(Label1 & Mid$(sMsg, nStartPos, 1), nTextDisplayLen)
End Sub
Hope that helps
~seawe
Edited by seaweed on 02-23-2000 at 03:30 PM