Rich Text box scroll to the bottom when new data is written to it

后端 未结 6 976
天命终不由人
天命终不由人 2020-12-05 22:43

My program calls Java and then redirects stdout to a RichTextBox. My problem is that the vertical scrollbar always stays at the top of the box every time data i

6条回答
  •  广开言路
    2020-12-05 22:50

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern IntPtr SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
        private const int WM_VSCROLL = 277;
        private const int SB_PAGEBOTTOM = 7;
    
        internal static void ScrollToBottom(RichTextBox richTextBox)
        {
            SendMessage(richTextBox.Handle, WM_VSCROLL, (IntPtr)SB_PAGEBOTTOM, IntPtr.Zero);
            richTextBox.SelectionStart = richTextBox.Text.Length;
        }
    

    ScrollToBottom(richTextBox);

    by using above method you can scroll rich text box to bottom

提交回复
热议问题