Joseph said:
I am trying to find the command to scroll the richtextbox to the latest
appended string at the bottom. I have tried update, refresh and scroll to
caret but it does not seem to work
Hi Joseph,
it only works if the RTF-Box has the focus (and therefore a caret).
Is that is a problem for you here is a small workaround using WinAPI
SendMessage:
using System.Runtime.InteropServices;
[...]
//WinAPI-Declaration for SendMessage
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(
IntPtr window, int message, int wparam, int lparam);
const int WM_VSCROLL = 0x115;
const int SB_BOTTOM = 7;
private void button1_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < 100; i++)
{
//Let's add some text to the rtfbox
richTextBox1.Text += "Hallo Welt ";
}
//Scroll to the bottom, without focus
SendMessage(richTextBox1.Handle, WM_VSCROLL, SB_BOTTOM, 0);
}
Cheers
Arne Janning