How to Scroll a Text in VB.Net
Scrolling text in a control using Visual Basic.NET is not as complicated as you may think. In order for you to scroll text, you're going to need to execute a section of code a number of times. The best way to do this is by using a "Timer" control in your application. You can start a timer to execute your code until the timer is stopped. The "Timer" control is invisible to the user, and it's commonly used for background processing.
Instructions
-
-
1
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 center of the dialog window, to create a new project.
-
2
Double-click "Timer" to add a timer to your form. Double-click "Label" to add a new label to your form. Add a button using the same technique. Double-click "Button1" to create a click event for this button.
-
-
3
Copy and paste the following code inside the button click event:
For index As Integer = 0 To UBound(textString)
Dim workedString As String = ""
workedString = scrollText.Substring(index) & " " & scrollText.Substring(0, index)
textString(index) = workedString
Next
Timer1.Interval = 75
Timer1.Enabled = True
Timer1.Start()
-
4
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:
xPos += 1
Dim tmrStr As String
tmrStr = textString(xPos)
Label1.Text = tmrStr
If xPos = UBound(textString) Then xPos = -1
-
5
Press "F5" to run the program, and click "Button1" to display scrolling text using the label.
-
1
References
- Photo Credit Photos.com/Photos.com/Getty Images