Click here to Skip to main content
13,346,397 members (64,769 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 29 Jun 2005

How to change scrollbars position in a multiline textbox

Rate this:
Please Sign up or sign in to vote.
A way to control a textbox's scrollbars position.


I have discovered a nice way to control multi-line textbox's scrollbars in C#. Here we can force the textbox's scrolls down to the end of the text, when we are showing the log file contents dynamically.

The code

First, we have to define a constant value:

const int EM_LINESCROLL = 0x00B6;

Then, we have to declare two external methods of user32.dll:

static extern int SetScrollPos(IntPtr hWnd, int nBar, 
                               int nPos, bool bRedraw);
static extern int SendMessage(IntPtr hWnd, int wMsg, 
                               int wParam, int lParam);

Finally, use these methods to do the real thing:


Done! Simple and easy!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Carlos Eugênio X. Torres
Web Developer
Portugal Portugal
View my bio at

You may also be interested in...


Comments and Discussions

QuestionEM_LINESCROLL what is it Pin
Peter Hawke27-Apr-12 14:55
memberPeter Hawke27-Apr-12 14:55 
QuestionHere is the VB version Pin
Peter Hawke27-Apr-12 14:52
memberPeter Hawke27-Apr-12 14:52 
GeneralGetScrollPos Pin
evilrifleman1-Jul-10 18:16
memberevilrifleman1-Jul-10 18:16 
QuestionHow to do the Horizontal Scroll? Pin
chrisliando25-Feb-08 18:49
memberchrisliando25-Feb-08 18:49 
AnswerRe: How to do the Horizontal Scroll? Pin
evilrifleman1-Jul-10 18:20
memberevilrifleman1-Jul-10 18:20 
QuestionMoving vertical scrollbar to the end of multi-line text box problem??? Pin
bishnupatro11-Feb-08 20:37
memberbishnupatro11-Feb-08 20:37 
GeneralSimple scroll Pin
ks_visa29-Nov-06 5:19
memberks_visa29-Nov-06 5:19 
GeneralOnly SendMessage does stuff Pin
ThomasKaiser11-Nov-05 16:21
memberThomasKaiser11-Nov-05 16:21 
QuestionWhy do it so difficult? Pin
Anonymous30-Jun-05 17:05
sussAnonymous30-Jun-05 17:05 
AnswerRe: Why do it so difficult? Pin
Carlos Eugênio X. Torres21-Jul-05 14:14
memberCarlos Eugênio X. Torres21-Jul-05 14:14 
GeneralRe: Why do it so difficult? Pin
NadaChaayaTadros2-Jun-06 1:31
memberNadaChaayaTadros2-Jun-06 1:31 
AnswerScrolling Horizontally.... Pin
Pradeep babu21-Jul-05 19:48
memberPradeep babu21-Jul-05 19:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 29 Jun 2005
Article Copyright 2005 by Carlos Eugênio X. Torres
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid