Missing something obvious - TextBox SetSel

Started by Rick McNeely, September 17, 2010, 12:10:27 PM

Previous topic - Next topic

Rick McNeely

I know I am missing something quite obvious here.  I have a textbox that I am sending information to.  I want it to set selection to the end of the text and to autoscroll to the end.  My code does set the selection point properly, I can scroll down and see the cursor at the end.  I can query the control and see that the selection point is proper, but the textbox doesn't scroll to the end.  Does the textbox need to have focus to autoscroll?

WS_HSCROLL, WS_VSCROLL, ES_MULTILINE, ES_AUTOHSCROLL, ES_AUTOVSCROLL, and ES_READONLY are checked.


Sub sendToRCV(msg As String)
    Dim i As Long
    Dim sStr As String
   
    'http://www.planetsquires.com/protect/forum/index.php?topic=2519.0
   
    sStr = FF_TextBox_GetText( HWND_FORM1_TBRCV ) & msg
    i = Len(sStr)
     
    FF_TextBox_SetText(HWND_FORM1_TBRCV, sStr)
   
    FF_TextBox_SetSel( HWND_FORM1_TBRCV, i, i )
   
End Sub


Rick

Roger Garstang

#1
Try it without AutoHScroll.  ES_WANTRETURN way be needed too. I do the same thing in my apps and I believe when that is enabled it won't scroll down.  I usually Set Sel to 65535 and before setting Selection I also check to see if text len is > 65000 and if so I do a Right$ to it at 32768 chars to always keep it clean and not have too much text in my log window.

Using FF_TextBox_ReplaceText is quicker too after setting sel to end than setting all the text each time.  You may also need an UpdateWindow call...I usually add it just to be safe.  While updating it is usually good to disable keys/mouse to the window too so people wont click and change insert position.

Add to CUSTOM for  Editbox:


Select Case wMsg
   Case %WM_LButtonDown, %WM_RButtonDown, %WM_MButtonDown, %WM_LButtonUp, %WM_RButtonUp, %WM_MButtonUp, %WM_KeyDown, %WM_KeyUp
      If Running Then Function= %TRUE ' Disable moving Cursor while Running
End Select

Roger Garstang

If it still doesn't work, I used to use:

SendMessage(hTextBox, %EM_SCROLLCARET, 0, 0) ' Scroll to Cursor

Rick McNeely

Roger,

Thanks a bunch!  Second post worked perfectly.  I should've mentioned that the control never has focus, and there is no direct user input.

I thought that textboxes were supposed to scroll to the selection point by default?

Rick

Roger Garstang

Mine scrolls only using the first post with WantReturn on and AutoHCcroll & HSCROLL off.