Automatic scroll in TextBox

Started by David Chisholm, November 13, 2012, 02:59:26 PM

Previous topic - Next topic

David Chisholm

I am using a TextBox to output the results of a rather long operation.  I want the text to automatically scroll up the screen one-line-at-a-time as it hits the bottom of the box.

I have tried checking the ES_AUTOVSCROLL within the (WindowStyles) but it does not seem to do anything.  I am updating the text box as per the example below by getting the text, appending to it and replacing all the text.  I did not see any kind of append command available.

Dim posn As Integer
   
    FF_TextBox_SetText(HWND_FORM1_TEXT1, "")

    For posn = 1 To 100
   
        FF_TextBox_SetText(HWND_FORM1_TEXT1, FF_TextBox_GetText(HWND_FORM1_TEXT1) & Str$(posn) & $CrLf )
   
    Next posn


By default the text disappears off the bottom of the box and the vertical scroll bar adjusts accordingly.

I want to be able to see the latest entry in the window without having to use the scroll bars.  I did try the scroll commands but I do not know how many lines will eventually be displayed and so my only workaround was to issue 10 or so (FF_TextBox_Scroll(HWND_FORM1_TEXT1, %SB_PAGEDOWN)) which is not very efficient and may not work if I get an extraordinary large number of output lines.

Any suggestions?

Thanks.
/Dave Chisholm

Paul Squires

Hi David,

I am just getting home from my trip. I haven't tried any code to post for your problem but you can start by looking at the text in these two posts:

http://www.planetsquires.com/protect/forum/index.php?topic=2675.msg20200#msg20200

http://www.planetsquires.com/protect/forum/index.php?topic=2519.msg19297#msg19297
Paul Squires
PlanetSquires Software

David Chisholm

Paul,

Thanks.  I looked at the two examples.  The for loop example with scrolling one line based on the line count was too jittery on the screen.

I tried passing "%EM_SCROLLCARET" through the FF_TextBox_Scroll until I realized, by clicking on the Code tab, that it was being converted to:

"SendMessage HWND_FORM1_TEXT1, %EM_SCROLL, %EM_SCROLLCARET, 0"  ARGHHHHHH!  Once I figured that out the following worked great:

    Dim end_of_text As Long   
   
    Dim posn As Integer
   
    FF_TextBox_SetText(HWND_FORM1_TEXT1, "")

    For posn = 1 To 30
   
        FF_TextBox_SetText(HWND_FORM1_TEXT1, FF_TextBox_GetText(HWND_FORM1_TEXT1) & Str$(posn) & $CrLf )
        end_of_text = Len(FF_TextBox_GetText(HWND_FORM1_TEXT1))
        FF_TextBox_SetSel(HWND_FORM1_TEXT1,end_of_text,end_of_text)
        SendMessage HWND_FORM1_TEXT1, %EM_SCROLLCARET, 0, 0
        FF_DoEvents
    Next posn


Maybe, in future releases, you could add FF_TextBox_ScrollCaret to your functions?

Thanks again for your quick reply and your help.
/Dave Chisholm