Creating a Visual Basic.NET application that auto scrolls text in a TextBox control can easily be accomplished using String arrays and a timer. A timer control in VB.NET will execute code continuously until the program ends. Use a String array to fill it with the text you want to scroll, and display different elements of the array in the TextBox using the timer to show the scrolling effect.
- Skill level:
Other People Are Reading
Launch Microsoft Visual Studio, click "New Project" from the left pane of your computer screen and expand "Visual Basic" below "Installed Templates." Click "Windows" and double-click "Windows Forms Application" from the centre of the dialogue window to create a new project.
Double-click "Timer" to add one to your form. Double-click "TextBox" to add a new text box to your form. Double-click the form to create a form load event.
Add the following code above the form load event to create three global variables, including the one that will hold your scrolling text:
Dim scrolling Text As String = "This is my scrolling text "
Dim txtStr(scrollingText.Length - 1) As String Dim txtPos As Integer = -1
Add the following code inside the form load event to loop through the scrolling text and start the timer:
For idx As Integer = 0 To UBound(txtStr) Dim worked String As String = "" worked String = scrollingText.Substring(idx) & " " & scrollingText.Substring(0, idx) txtStr(idx) = worked String Next Timer1.Interval = 75 Timer1.Enabled = True Timer1.Start()
Switch back to form design view and double-click "Timer1" to create a tick event for the timer. Add the following code inside the event:
txtPos += 1 Dim timerStr As String timerStr = txtStr(txtPos) Label1.Text = timerStr If txtPos = UBound(txtStr) Then txtPos = -1
Press "F5" to run the program and display scrolling text using the text box.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for