Disabling the RichTextBox AutoCard

I am using a RichTextBox control to display application logs. I update the control once per second with several calls to the RichTextBox :: AppendText method. What really annoys me is that the cursor continues to scroll to the last line of text. Its very inconvenient in a situation where the user needs to analyze the logs that are in the beginning. I tried to solve my problem:

int pos = tb_logs.SelectionStart;
tb_logs.AppendText("log message");
tb_logs.SelectionStart = pos;

This is not the essence of the problem, because the management periodically redraws, which is very distracting. Are there any cleaner solutions?

+5
source share
2 answers

" " , , :

VScroll, TextChanged

richTextBox1.VScroll += HandleRichTextBoxAdjustScroll;
richTextBox1.TextChanged += HandleRichTextBoxAdjustScroll;

private const UInt32 SB_TOP = 0x6;
private const UInt32 WM_VSCROLL = 0x115;

[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", SetLastError = true)]
private static extern bool PostMessage(IntPtr hWnd, UInt32 Msg,
    IntPtr wParam, IntPtr lParam);

private void HandleRichTextBoxAdjustScroll(Object sender,
    EventArgs e)
{
    PostMessage(handle, WM_VSCROLL, (IntPtr)SB_TOP, IntPtr.Zero);
}

. WM_VSCROLL WM_HSCROLL SB_TOP SB_LEFT

private const UInt32 WM_HSCROLL = 0x0114;
private const UInt32 SB_LEFT = 0x06;
+7

tb_logs.SelectionLength = 1; SelectionStart. 1 char .

...

0

All Articles