IIM Home


Home
Members
Archive
Discussions
Screen Shots
Code Outline
C# Recipes
Contact Information

One of the things that was the hardest to do in IIM was to find a reliable way to scroll the chat text box to the end of the newest text.  I found quite a few 'solutions' on the web, and most of them barely worked.  The best one I found was this one.  I cannot find the source of it on Google, so perhaps it's disappeared since I found it.  To get this to work, create your own class extending the TextBox or RichTextBox Class and add this inside it.  This one really seems like an oversight on Microsoft's part, this should have been included in the .Net framework from 1.0.
 

#region Scroll To End
public void ScrollToEnd()
{
      try
      {
            // place our cursor at the end of the text
            base.SelectionStart = base.Text.Length;
            // create a new message to scroll to the
            // bottom of the textbox
            Message m = Message.Create(base.Handle,277/*WM_VSCROLL*/,(IntPtr)7/*SB_BOTTOM*/,IntPtr.Zero);
 
            // send the message to scroll to the bottom of the textbox.
            base.WndProc(ref m);
      }
      catch (Exception e)
      {
            log.Error("Exception scrolling to end",e);
      }
}
#endregion


Home | Members | Archive | Discussions | Screen Shots | Code Outline | C# Recipes | Contact Information

 Copyright 2004 The Tiny Custom Software Company.
For problems or questions regarding this Web site contact Project Admin Email.
Last updated: 01/02/05.

Free Site Counters