Re: Allow RichTextBox Scrollbar to control another RTB scroll
I'll try to learn from it. I might come back to this thread to ask you a few things about the code as well, if you have the time to help me understand anything I don't know.
Thanks though I appreciate that.
After Testing: It does appear that the mouse scroll is laggy by a bit. It's only behind by one tick on my scroller though. Somehow it's getting delayed. I also noticed that it's not quite realtime with the side scroll when manually scrolling with the bar. It adusts after the mouse up event, and the scroller doesn't change with the up or down arrows when the screen goes up or down within the content area. This is going to be quite a trick, I always wondered how of what they did with a program like Notepad++ to get everything in sync as though they were only one control... This is an advancement to what I had before though.
Last edited by AceInfinity; Jun 22nd, 2011 at 10:28 PM.
Re: Allow RichTextBox Scrollbar to control another RTB scroll
Originally Posted by AceInfinity
It does appear that the mouse scroll is laggy by a bit. It's only behind by one tick on my scroller though. Somehow it's getting delayed.
Not sure exactly how to fix that but I noticed if you change the RTB smooth scrolling to single line scrolls instead then the mousewheel works much better.
Code:
' add to top of rtbEx.vb,
Private Const EM_SCROLL As Int32 = &HB5
Private Const SB_LINEDOWN As Int32 = 1
Private Const SB_LINEUP As Int32 = 0
' change rtbEx.vb,
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
' change mousewheel msgs to scroll one line instead of smooth scrolls.
If m.Msg = WM_MOUSEWHEEL Then
m.Msg = EM_SCROLL
m.LParam = IntPtr.Zero
If (m.WParam.ToInt32) / 65536 > 0 Then ' wheel direction upward
m.WParam = CType(SB_LINEUP, IntPtr)
Else ' wheel direction downward
m.WParam = CType(SB_LINEDOWN, IntPtr)
End If
End If
MyBase.WndProc(m)
' detect EM_SCROLL here
If m.Msg = WM_VSCROLL OrElse m.Msg = WM_HSCROLL OrElse m.Msg = EM_SCROLL Then
SendScrollPosMessage(scrollMatchedControl.Handle, EM_SETSCROLLPOS, New IntPtr(0), scrollHandler.getScrollValues(Me.Handle))
End If
End Sub
Re: Allow RichTextBox Scrollbar to control another RTB scroll
Hmm, you have a point, and I could see how that would be much more beneficial for my purposes as well, it would keep the mouse scrolling more in sync with the lines in my control. I'll test it out, and based on that idea, I could probably think of a way to add another extra bonus function for changing the number of lines to scroll from each mouse scroll "tick" just like in the general mouse options for Windows.
I did manage to get a little better control of the synced scrolling, but I'm not sure on how I could get them to scroll together by using the up and down arrows. If I figure that out I'll post here with my finalized code to help others out too.
Re: Allow RichTextBox Scrollbar to control another RTB scroll
Originally Posted by AceInfinity
I did manage to get a little better control of the synced scrolling, but I'm not sure on how I could get them to scroll together by using the up and down arrows. If I figure that out I'll post here with my finalized code to help others out too.
Just curious, have you tried the clsRTFScrollSync class? I tried it in WinXP-32 only with VB10 and the scrollthumbs, keyboard arrows/page Up/Down and even the middle mouse arrow thingy kept both RTBs scrollbars in sync.
One problem I ran into in VB10 with Option Strict On was that VB complains of late binding in the Public Sub AddControl, tho haven't bothered to figure out how to fix that as I really have no use for this.
I setup two RTBs the same and tried it like this,
Code:
Private objScrollSync As New clsRTFScrollSync
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
objScrollSync.ScrollBarToSync = ScrollBars.Both
objScrollSync.AddControl(RichTextBox1)
objScrollSync.AddControl(RichTextBox2)
End Sub
Re: Allow RichTextBox Scrollbar to control another RTB scroll
I'm using a trick method that seems to kind of work, suggested by another member here, I think paul already gave me that method, and it did work, but it was a bit laggy