13 Replies - 5775 Views - Last Post: 29 June 2011 - 04:18 PM Rate Topic: -----

#1 TheRandomNoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-June 11

Automatic Scrolling Textbox

Posted 29 June 2011 - 06:46 AM

In my current for (Form1) I have a textbox (textbox1) containing more text than is visible. I've seen it before where programs can have automatically looped scrolling textboxes, and was wondering how one would go about doing this? What I mean is something that scrolls to line 2, then 3, then 4, then 5, then 6, then 7 etc until it loops back to line 1. Thanks in advance.
P.S I also want this to be on form load, not on a button press.
Is This A Good Question/Topic? 0
  • +

Replies To: Automatic Scrolling Textbox

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 07:20 AM

I would suggest investing some time looking into the 'timer' object. You can set it so that every 'tick' that goes off it would move the scroll line down. Once it ticks and it's at the bottom it scrolls up all the way to the top!
Was This Post Helpful? 1
  • +
  • -

#3 TheRandomNoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-June 11

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 08:45 AM

View Postmodi123_1, on 29 June 2011 - 07:20 AM, said:

I would suggest investing some time looking into the 'timer' object. You can set it so that every 'tick' that goes off it would move the scroll line down. Once it ticks and it's at the bottom it scrolls up all the way to the top!


Thanks a lot I'll definitely look into using the timer in that way. Have you got any references that I could look at, or any example codes as I can't seem to find anything like this out there.
Was This Post Helpful? 0
  • +
  • -

#4 TheRandomNoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-June 11

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 08:58 AM

View Postmodi123_1, on 29 June 2011 - 07:20 AM, said:

I would suggest investing some time looking into the 'timer' object. You can set it so that every 'tick' that goes off it would move the scroll line down. Once it ticks and it's at the bottom it scrolls up all the way to the top!


Nevermind I worked it out. Thanks a lot for this, it's really helpful.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 09:01 AM

You mean outside of the help MSDN provides, right?

http://msdn.microsof...orms.timer.aspx
Was This Post Helpful? 0
  • +
  • -

#6 TheRandomNoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-June 11

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 11:37 AM

View Postmodi123_1, on 29 June 2011 - 09:01 AM, said:

You mean outside of the help MSDN provides, right?

http://msdn.microsof...orms.timer.aspx


Yeah, I looked over that and thought I was onto something but I wasn't. I used a panel along with a timer and autoscroll, but this just scrolled my textbox and didn't show any text that was lower that visible on the screen. I even tried using a rich text box, adding a timer with a delay of 200 and using this code:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If RichTextBox1.Top = -RichTextBox1.Height Then
            RichTextBox1.Top = Panel1.Height
        Else
            RichTextBox1.Top -= 1
        End If
    End Sub

but that still didn't work out. Again, the actual textbox scrolled, not the text inside it.
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 11:41 AM

I thought that's what you wanted. Scrolled text in a text box... that uses the scrollbars.

If you want strings of words to appear in a specific order then use a one line text box (or label) for display... and then have an array of strings set up.

Timer ticks
current_message increments
if current_message is greater than the number of strings in the array set to zero.
textbox/label gets the value of array_of_strings(current_message)

repeat.
Was This Post Helpful? 1
  • +
  • -

#8 TheRandomNoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-June 11

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 11:47 AM

View Postmodi123_1, on 29 June 2011 - 11:41 AM, said:

I thought that's what you wanted. Scrolled text in a text box... that uses the scrollbars.

If you want strings of words to appear in a specific order then use a one line text box (or label) for display... and then have an array of strings set up.

Timer ticks
current_message increments
if current_message is greater than the number of strings in the array set to zero.
textbox/label gets the value of array_of_strings(current_message)

repeat.


I don't intend for it to be single line though. The textbox loads it's text from a file, and I want that text to be automatically scrolled to the bottom, then to the top again.
Was This Post Helpful? 0
  • +
  • -

#9 TheRandomNoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-June 11

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 11:53 AM

View Postmodi123_1, on 29 June 2011 - 11:41 AM, said:

I thought that's what you wanted. Scrolled text in a text box... that uses the scrollbars.

If you want strings of words to appear in a specific order then use a one line text box (or label) for display... and then have an array of strings set up.

Timer ticks
current_message increments
if current_message is greater than the number of strings in the array set to zero.
textbox/label gets the value of array_of_strings(current_message)

repeat.


Nevermind, after a lot of thought I finally got it sorted. Thanks a lot for being so tolerant. Here's the code I used:

 Structure POINT
        Dim x As Integer
        Dim y As Integer
    End Structure

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim p As New POINT
        SendMessage(RichTextBox1.Handle, EM_GETSCROLLPOS, 0, p)
        p.y += 1
        SendMessage(RichTextBox1.Handle, EM_SETSCROLLPOS, 0, p)
    End Sub
    Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByRef lParam As POINT) As Integer

    Const EM_GETSCROLLPOS As Integer = 1245
    Const EM_SETSCROLLPOS As Integer = 1246

Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8955
  • View blog
  • Posts: 33,571
  • Joined: 12-June 08

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 12:09 PM

Mkay.. Seems a bit excessive.. I was going to suggest the text box has a "scroll to caret" that I was able to utilize for it. For ten minutes of work it seemed to function pretty well.
Was This Post Helpful? 1
  • +
  • -

#11 dbasnett  Icon User is offline

  • D.I.C Addict

Reputation: 108
  • View blog
  • Posts: 601
  • Joined: 01-October 08

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 12:48 PM

I would have picked richtextbox and scrolltocaret...
Was This Post Helpful? 1
  • +
  • -

#12 TheRandomNoob  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 28-June 11

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 03:11 PM

View Postdbasnett, on 29 June 2011 - 12:48 PM, said:

I would have picked richtextbox and scrolltocaret...


I tried scrolltocaret but couldn't seem to get it to function properly. This code I have functions fine, but doesn't loop yet so if there's an easy way I'd like to explore it. Exactly how would you suggest using scrolltocaret in this application?
Was This Post Helpful? 0
  • +
  • -

#13 dbasnett  Icon User is offline

  • D.I.C Addict

Reputation: 108
  • View blog
  • Posts: 601
  • Joined: 01-October 08

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 03:38 PM

This illustrates how it works, but may not be what you want

        'test data to append to RTB
        Dim ipsum As String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

        RichTextBox1.AppendText(String.Join(Environment.NewLine, ipsum.Split(New Char() {" "c, ","c}, StringSplitOptions.RemoveEmptyEntries)))
        RichTextBox1.AppendText(Environment.NewLine)
        RichTextBox1.AppendText("*")
        RichTextBox1.ScrollToCaret()


Was This Post Helpful? 1
  • +
  • -

#14 smohd  Icon User is offline

  • Critical Section
  • member icon


Reputation: 1817
  • View blog
  • Posts: 4,625
  • Joined: 14-March 10

Re: Automatic Scrolling Textbox

Posted 29 June 2011 - 04:18 PM

Is it must to use textBox or RtextBox? I mean are you getting data from user or you load them from somewhere?
If your data are loaded from somewhere why dont you use ListBox instead? After feeding its data by
 ListBox1.Items.Add("line1") 
you can change its selected index by saying
 ListBox1.SelectedIndex = index 
either in loop or in timer_tick event and just updating its value (index)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1