This topic is now archived and is closed to further replies.


Automatically Scrolling A RichTextControl in .Net

Recommended Posts

Telamon    157
Hi. I have a very simple problem that is driving me crazy. I''m writing a simple output console that my program occasionally prints to (this is using C#). The console is nothing more than a regular RichTextControl. My Problem: When I append text into the control (and it at the end), I want the control to scroll all the way down to the bottom, so that the newly added text is visible. I''ve looked through all the .Net docs and there doesn''t seem to be anything that lets me programmatically move the scroll bar. I found ScrollToCaret(), but that will only work if the textbox has focus. I''ve come across this problem before in a project when I was using C++ and MFC. The actual solution I came up with then involved getting the handle to the vertical scroll in the textbox using some WinAPI voodoo and then manually adjusting it''s value using another arcane function call. I don''t really want to pollute my beautiful C# code with WinAPI calls, but even if I did want to try doing it this way, I have no way of getting the VScrollbar''s handle short of some hack like manually searching through all the windows currently allocated and finding one of the right width and height. Help! ---------------------------------------- Let be be finale of seem, seems to me. ---------------------------------------- Coding: Miscellany:

Share this post

Link to post
Share on other sites
Arild Fines    968

private void scrollToBottom()
SendMessage( this.richTextBox.Handle, WM_VSCROLL, SB_BOTTOM, 0 );

private static extern int SendMessage( IntPtr hWnd, uint msg, int wparam, int lparam );

private const int WM_VSCROLL = 0x0115;
private const int SB_BOTTOM = 7;

Share this post

Link to post
Share on other sites