2012-05-18 4 views
2

richTextbox1에 많은 텍스트를 추가하면 오른쪽에 스크롤 막대가 있지만 그 안에 텍스트는 모든 시간을 추가하는 선입니다. 마우스 오른쪽 버튼으로 드래그하면 텍스트 스크롤이 보입니다.richTextBox 스크롤을 만드는 방법은 무엇입니까?

내부의 텍스트가 richTextbox의 맨 아래에 오면 자동으로 스크롤을 만들고 싶습니다.

어떻게 할 수 있습니까?

+0

google이 내게 준 : http://geekswithblogs.net/Waynerds/archive/2006/01/29/67506.aspx – deostroll

답변

3

텍스트가 RichTextBox 컨트롤에 추가 될 때마다 RichTextBox의 텍스트 끝 부분에서 커서를 이동하려면 이러한 명령문을 실행해야합니다. RichTextBox 컨트롤의 이름이 richTextBox라고 가정하면 아래와 같은 명령문을 사용할 수 있습니다.

richTextBox.SelectionStart = richTextBox.Text.Length; 
richTextBox.ScrollToCaret(); 
2

이 코드는 완벽하게 작동합니다 ------

namespace CustomRTB 
{ 
    public class CustomRTB : RichTextBox 
    { 
     #region API Stuff 
     [DllImport("user32.dll", CharSet = CharSet.Auto)] 
     public static extern int GetScrollPos(IntPtr hWnd, int nBar); 

     [DllImport("user32.dll")] 
     private static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool bRedraw); 

     private const int SB_HORZ = 0x0; 
     private const int SB_VERT = 0x1; 
     #endregion 
     public int HorizontalPosition 
     { 
      get { return GetScrollPos((IntPtr)this.Handle, SB_HORZ); } 
      set { SetScrollPos((IntPtr)this.Handle, SB_HORZ, value, true); } 
     } 

     public int VerticalPosition 
     { 
      get { return GetScrollPos((IntPtr)this.Handle, SB_VERT); } 
      set { SetScrollPos((IntPtr)this.Handle, SB_VERT, value, true); } 
     } 
    } 
} 

당신이

공공 RichTextBoxScrollBars 스크롤바를 포함 를 RichTextBox 클래스 속성을 확인할 수 있습니다 {얻을; 세트; }

이 속성을 사용하면 RichTextBox 컨트롤의 사용자에게 스크롤 할 수 있도록 가로 및 세로 스크롤 막대를 제공 할 수 있습니다.

관련 문제