C# Scroll To End Text Box

10 Aug

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
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.

Leave a comment

Posted by on August 10, 2011 in .net, c#


Tags: , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: