The only way I found to do this was to use the SendMessage API to send an
EM_LINESCROLL message. In my case I was always adding just one line at a
time so the following code worked:
[DllImport("user32.dll",EntryPoint="SendMessage")]
static extern int SendMessage(IntPtr Handle, int Msg, int WParam, int
LParam);
const int EM_LINESCROLL = 0xB6;
....
// After appending a line of text to the RichText control
SendMessage(richText1.Handle, EM_LINESCROLL, 0, 1);
If you're adding more than one line at a time, or if you want to scroll to
the end even if the user has scrolled away from the end, then you will need
to be a bit more clever and work out exactly how many lines you need to
scroll by.
Chris Jobson
"JRB" <JR*@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
I have a thread adding lines of text to a richtextbox on my windows form
about every 1 second. I want the last line of text to always be visible,
which it is until the box gets filled up. The last line is always visible
if
the cursor is on the richtextbox, But if I'm working on another
richtextbox
on the form, the one that is continually getting text doesn't scroll down
automatically. Is there any way to get it to automatically show the last
thing added to the richtextbox? I've tried scrollToCaret already, but if
the
focus isn't on that richtextbox it sill doesn't work. Thanks.
JRB