Jump to content
  • Advertisement

Archived

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

Telamon

Automatically Scrolling A RichTextControl in .Net

This topic is 5294 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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: http://www.stanford.edu/~jjshed/coding Miscellany: http://www.stanford.edu/~jjshed

Share this post


Link to post
Share on other sites
Advertisement

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

[DllImport("User32.dll")]
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!