Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set scroll position in a textbox

Status
Not open for further replies.

mcbigj

Programmer
Dec 14, 2001
83
0
0
US
Hello,

I'm trying to set the scroll postion in a rich text box. Unfortunately the richtextbox control does not include the autoscroll method where I could set the x and y points and have it scroll to that position. I assume I need to inherit or implement another control or something like that. I'm just not sure where to start. Could anyone please point me in the right direction?

Thanks,

John
 
' See TextBoxBase.SelectionStart
Note You can programmatically move the caret within the text box by setting the SelectionStart to the position within the text box where you want the caret to move to and set the SelectionLength property to a value of zero (0). The text box must have focus in order for the caret to be moved.

rtf.Focus() ' No scroll if no focus
rft.SelectionLength = 0
' Get to end first so actual positon will be
' visible at the top rather than top
rtf.SelectionStart = 99999999
rtf.SelectionStart = whereever



Compare Code
 
I'll look at that thanks. The problem is though, I should have mentioned, is that I actually want the selection to be in the middle of the textbox. What happens now, is when I do textbox1.ScrollToCaret for instance, if the caret is below the visible textbox area, it scrolls to the point but that point displays at the bottom of the textbox area when I would prefer it to be viewable around the middle of the area. Hope that makes sense. any ideas?
 
take the number of visible lines divided by 2 and move the cursor down that many lines, then ScrollToCaret, then move the cursor back up.

-Rick

----------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top