After appending text to a text box, you may want to scroll to the end of that box. Here’s some code that will accomplish this (remember to include, System.Runtime.InteropServices in your using header):
///
/// Function import to automatically scroll down rich text boxes.
///
/// handle to destination window
/// message
/// first message parameter
/// second message parameter
///
[DllImport("user32.dll")]
public static extern int SendMessage(
IntPtr hWnd, // handle to destination window
int Msg, // message
IntPtr wParam, // first message parameter
IntPtr lParam // second message parameter
);
///
/// Automatically scroll down rich text boxes.
///
/// The windows handle of a text box.
public void ScrollToEnd(IntPtr Handle)
{
int WM_VSCROLL = 0x115;
int SB_BOTTOM = 7;
SendMessage(Handle, WM_VSCROLL, (IntPtr)SB_BOTTOM, IntPtr.Zero);
}
// Using the method.
ScrollToEnd(richTextBox1.Handle)