Results 1 to 7 of 7

Thread: Automatically Scrolling to the bottom of a text box

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    Cordova, TN
    Posts
    60

    Lightbulb Automatically Scrolling to the bottom of a text box

    Just outta curiosity, is there anyway i can get a text box to automatically scroll to the end when a text file is loaded into it? If i can get it to do that, then it'll make it alot more convenient for the people in my department that use the log viewer i made for my program. There's several thousand words in the file now.
    How come it's a penny for your thoughts, but you have to put your 2 cents in? Somebody's makin' a penny

  2. #2
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425
    yes, there is...

    Just set the selection starting point to the end of the text...

    VB Code:
    1. Text1.SelStart = Len(Text1.Text)
    "Experience is something you don't get until just after you need it."

  3. #3

    Thread Starter
    Member
    Join Date
    Sep 2002
    Location
    Cordova, TN
    Posts
    60
    I tried doing that, but it's not working when the form loads. But if i reload the text file, it does work. Is there a way to get it work when the form loads? I tried it in 2 different places:

    VB Code:
    1. Dim lngCharacters As Long
    2.    
    3.     'Open log file for input so it can be loaded into the text
    4.     'field.
    5.     Open "G:\COMMON\AOPS\A-Ops Incidents Report\LOGS\Incident Report.txt" For Input As #1
    6.         txtLogComments.Text = Input(LOF(1), 1)
    7.         lngCharacters = LOF(1) / 8
    8.         lblCharacters.Caption = lngCharacters & " Words Loaded"
    9.     Close #1
    10.    
    11.     'Automatically Scroll to the bottom of the text display
    12.     txtLogComments.SelStart = Len(txtLogComments.Text)

    Thats the code from the form that actually has the text box on it. The other way i tried it is trying to do it from the form thats calling it which is the main form:

    VB Code:
    1. Load frmLogViewer
    2.     'Automatically Scroll to the bottom of the text display
    3.     frmLogViewer.txtLogComments.SelStart = Len(frmLogViewer.txtLogComments.Text)
    4.     frmLogViewer.Visible = True

    Does anyone know why it doesn't work from the formload event? And how can i get it to work from the formload event? Thanks.
    How come it's a penny for your thoughts, but you have to put your 2 cents in? Somebody's makin' a penny

  4. #4
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    try refreshing:

    VB Code:
    1. txtLogComments.SelStart = Len(txtLogComments.Text)
    2. txtLogComments.Refresh

  5. #5
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425
    Originally posted by Muddy
    try refreshing:

    VB Code:
    1. txtLogComments.SelStart = Len(txtLogComments.Text)
    2. txtLogComments.Refresh
    Hmm, good one, have to remember that one, don't know if it works though.

    What you could do is place a timer on the form, set the interval to 1 microsecond and load the textboxt in it's event...
    "Experience is something you don't get until just after you need it."

  6. #6
    Frenzied Member Spajeoly's Avatar
    Join Date
    Mar 2003
    Location
    Utah
    Posts
    1,068
    Make sure you have Shadows code in the Change sub of the textbox also.

  7. #7
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    The Netherlands
    Posts
    425
    By the way, remember that the text control can not have unlimited amound of characters. It's limitation can be found in the help or MSDN...

    If you put in more characters than it can handel you get an overflow...
    "Experience is something you don't get until just after you need it."

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