Results 1 to 7 of 7

Thread: Scrolling text

  1. #1

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Scrolling text

    I have a text box that displays text that updates on a timer every second, but it accumulates a lot of text, and every time it updates, it scrolls back up to the top of the box, so it's impossible to read anything new after the bottom of the box. Any idea of a code to automatically scroll to the end of the text that I could put at the end of the timer code? Thanx

  2. #2
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Scrolling text

    Put this in Text1_Change()

    Text1.selstart = len(text1.text)

  3. #3

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Exclamation Re: Scrolling text

    Thanx, That works o.k. i guess. Exactly what i asked for, but now I see what it does, is there a way to make it keep the scrolling where it is, otherwise you cant go back up to see other messages. I was thinking maybe ther's a way to find whee the cursor is (or how far the scroll bar is scrolled), store that, then recall it as the .selstart?THanx
    Last edited by ididntdoit; Apr 17th, 2006 at 01:03 PM.

  4. #4
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Scrolling text

    Try this
    VB Code:
    1. 'Declare these functions, etc etc
    2. Private Declare Function GetScrollRange Lib "user32" (ByVal hwnd As Long, ByVal nBar As Long, lpMinPos As Long, lpMaxPos As Long) As Long
    3. Private Declare Function GetScrollPos Lib "user32" (ByVal hwnd As Long, ByVal nBar As Long) As Long
    4.  
    5. Private Sub Display_Change()
    6. Dim MaxRange As Long
    7. Dim MinRange As Long
    8.  
    9. 'Get the total range of the textbox
    10. GetScrollRange Display.hwnd, 1, MinRange, MaxRange
    11.  
    12. 'If the the scroll bar is scrolled down to the bottom, or if the scroll bar is at the very top (Which most likely wont even happen except at the very start of the textbox creation)
    13. If Not GetScrollPos(Display.hwnd, 1) < MaxRange - 594 Or GetScrollPos(Display.hwnd, 1) = 0 Then
    14.     Display.SelStart = Len(Display.Text)
    15. End If
    16.    
    17. End Sub

    Display was the name of my textbox, so just replace it with the name of yours.
    Also, with the -594, it'll be different depending on the size of your textbox. I'm not sure of the 'real' way to calculate this, but what i did was add
    VB Code:
    1. Me.caption = GetScrollPos(Display.hwnd, 1) & "/" & MaxRange
    just above
    VB Code:
    1. GetScrollRange Display.hwnd, 1, MinRange, MaxRange

    Once the textbox fills up, and the scroll bar appears, write down the 2 values, and find the difference between them, that's the number you'll need to subtract.

    Goodluck

  5. #5

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Exclamation Re: Scrolling text

    Looks good, but it seems to do the exact same thing in the program- it always scrolls right to the end. Is it a typo on my part-
    VB Code:
    1. Private Sub Text2_Change()
    2. Dim MaxRange As Long
    3. Dim MinRange As Long
    4.  
    5. 'Get the total range of the textbox
    6. Text1.Text = GetScrollPos(Text2.hwnd, 1) & "/" & MaxRange
    7. GetScrollRange Text2.hwnd, 1, MinRange, MaxRange
    8.  
    9. 'If the the scroll bar is scrolled down to the bottom, or if the scroll bar is at the very top (Which most likely wont even happen except at the very start of the textbox creation)
    10. If Not GetScrollPos(Text2.hwnd, 1) < MaxRange Or GetScrollPos(Text2.hwnd, 1) = 0 Then
    11.     Text2.SelStart = Len(Text2.Text)
    12. End If
    13.  
    14. End Sub()

    or is there a problem with the code? Thanx.

  6. #6
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Scrolling text

    VB Code:
    1. If Not GetScrollPos(Text2.hwnd, 1) < MaxRange
    You forgot to subtract the difference between
    Maxrange and GetScrollPos(Text2.hwnd, 1)

  7. #7

    Thread Starter
    Fanatic Member ididntdoit's Avatar
    Join Date
    Apr 2006
    Location
    :uoıʇɐɔoן
    Posts
    765

    Re: Scrolling text

    Stilld does exact same thing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width