richtextbox scrolling by code

L

Larry Hilley

I have a richtextbox with a large amount of text in it that has scroll bars
to control what is in view.

I want to find text and then move it into view.

How do I control the document in the richtextbox so that when I find
something I want it display I can move it into view by code?

Thanks!

Larry Hilley
 
N

Nicholas Paldino [.NET/C# MVP]

Larry,

You could move the caret to the position that you want, and then call
the ScrollToCaret method on the RichTextBox class. However, this has the
side effect of moving the caret (which you might not want).

You might also be able to send the WM_HSCROLL or WM_VSCROLL messages to
the textbox to force it to scroll to the appropriate position.

Hope this helps.
 
L

Larry Hilley

Hi!
That did help. From your comment I had to go find out how to move the
caret.
I found SelectionStart moves it. It looks like just moving the caret
also puts that text in view.

Thanks

Larry Hilley
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top