puydan puydan - 4 months ago 67
C# Question

How to use Vscroll to scroll all richTextbox in the same time?

Is it possible to do it? scroll all richTextbox in the same time with Vscrollbar. I have 8 richTextbox to do with it. Any idead of this?

Ps. Now, I've trying sync textbox class to sync textbox scroll
http://stackoverflow.com/a/3823319/6811731 But it's seem doesn't work for me. Anyway, I decided to use vscroll instead.

Jim Jim

Try something like this:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, ref Point lParam);

private const int EM_SETSCROLLPOS = 0x4DE;

private Point p;

private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
    p.Y = e.NewValue;

    SendMessage(richTextBox1.Handle, EM_SETSCROLLPOS, IntPtr.Zero, ref p);
    SendMessage(richTextBox2.Handle, EM_SETSCROLLPOS, IntPtr.Zero, ref p);