This project is read-only.

Sync scrolling between 2 ScintillaNet

Topics: Developer Forum
Oct 18, 2012 at 2:56 PM


I use ScintillaNet for diff.

I have 2 ScintillaNet: scintilla1 and scintilla2
Both 2 text instances has the same line number and the same style.

I wish to autoscroll scintilla2 when I scroll scintilla1, and reverse.Have you got any idea about how to do this?

Thanks in advance.

Oct 18, 2012 at 3:36 PM

Add an event handler to each control's scroll event to do the scrolling for the other control.

To scroll a control in code use Scrolling.ScrollBy

Oct 19, 2012 at 8:48 AM

Hi david, and thanks for your answer.

Now new problem: the Scroll event fires when we click in the vertical scrollbar, but not when we perform a mousewheel.

Is it a bug, or did I missed something?

Oct 19, 2012 at 9:09 AM

Yeh just add the WM_MOUSEWHEEL to the WndProc in Scintilla to fire the scroll event

Oct 19, 2012 at 9:17 AM

Yep, but how do we do that?

Oct 19, 2012 at 10:03 AM

In Scintilla.cs in WndProc method you need:


  if (m.Msg == NativeMethods.WM_HSCROLL || m.Msg == NativeMethods.WM_VSCROLL ||
                m.Msg == NativeMethods.WM_WHEEL
                || m.Msg == NativeMethods.WM_KEYDOWN)
                FireScroll(ref m);
                //	FireOnScroll calls WndProc so no need to call it again
Oct 19, 2012 at 10:14 PM

You'll probably need to go one step further than just watching the scroll bars and mouse wheel. Last I checked, you can use the arrow keys or page up/down and it won't raise any scroll event.

The only reliable way that I'm aware of is to listen to the Scintilla.NativeInterface.UpdateUI event. This fires on every UI change so it doesn't always mean the display has scrolled. To know that you'll need to track previous scroll positions.