locked
Auto-scroll Text in Textboxes RRS feed

  • Question

  • How can I make the text in a textbox automatically scroll the text contained in it? I want it to stay a single line textbox, but all of the text won't show without doing something like this. I looked at things like marquee but it doesn't work for what I want.

     

    Thanks

    Sunday, July 1, 2007 11:46 PM

Answers

  •  

    You could put each line of text into a string array and use a Timer to place each line into the textbox:

     

        Dim iCount As Integer
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Try
                TextBox1.Text = MyStringArray(iCount)
                iCount += 1
            Catch ex As Exception
                Timer1.Enabled = False
            End Try
        End Sub

    Monday, July 2, 2007 9:00 PM
  •  

    Put a button and a Timer control on a form and paste in this code. This should give you a little idea of what you can do with both an array and a timer.

     

    Dim iCount As Integer = 0

    Dim MyStringArray() As String

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       For i As Integer = 0 To 9

          ReDim Preserve MyStringArray(i)

          MyStringArray(i) = "This is line number " & i

       Next

       Timer1.Interval = 1000

       Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

       Try

          TextBox1.Text = MyStringArray(iCount)

          iCount += 1

       Catch ex As Exception

          Timer1.Enabled = False

       End Try

    End Sub

    Friday, July 6, 2007 12:40 PM

All replies

  •  

    You could put each line of text into a string array and use a Timer to place each line into the textbox:

     

        Dim iCount As Integer
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Try
                TextBox1.Text = MyStringArray(iCount)
                iCount += 1
            Catch ex As Exception
                Timer1.Enabled = False
            End Try
        End Sub

    Monday, July 2, 2007 9:00 PM
  • What do I put for 'MyStringArray'? Is that something special that I need to create that has my text? If so how do I create it? Or do I just put the text in that I want displayed? I tried doing that and the timer didn't work

     

    Wednesday, July 4, 2007 3:52 PM
  •  

    Put a button and a Timer control on a form and paste in this code. This should give you a little idea of what you can do with both an array and a timer.

     

    Dim iCount As Integer = 0

    Dim MyStringArray() As String

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

       For i As Integer = 0 To 9

          ReDim Preserve MyStringArray(i)

          MyStringArray(i) = "This is line number " & i

       Next

       Timer1.Interval = 1000

       Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

       Try

          TextBox1.Text = MyStringArray(iCount)

          iCount += 1

       Catch ex As Exception

          Timer1.Enabled = False

       End Try

    End Sub

    Friday, July 6, 2007 12:40 PM