How to Auto Scroll Text in a Textbox Using VB.NET

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Auto Scroll Text in a Textbox Using VB.NET
Learn how to use a timer control in Visual Basic. (Comstock/Comstock/Getty Images)

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


  1. 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 centre of the dialogue window to create a new project.

  2. 2

    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.

  3. 3

    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
  4. 4

    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
        Timer1.Interval = 75
        Timer1.Enabled = True
  5. 5

    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
  6. 6

    Press "F5" to run the program and display scrolling text using the text box.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.