Keep vertical sync between multiple RichTextBoxes

hey guys,

i have 6 side to side rtb's, im trying to keep the same vertical position for each of them. only the left most rtb actually has a visible scroll bar, the others do not. the idea is that as soon as the scroll changes in any of the rtb's, to set the same position in the rest.

so far my solution works...sort'of'ish. the problem im having is that when the scroll position changes, my rtb's freak out a little (the vertical position bounces around like crazy for about 500ms) and then end up at the right position eventually. i need a solution for this because for some reason during this little freak out session, my .SelectionStart property is getting set to 0 and causing problems elsewhere in my code.

    Private Sub rtbEditCol_VScroll(ByVal sender As Object, ByVal e As System.EventArgs)
            If bEditColXVScroll_Busy = False Then
                If CheckIfSameNoOfLinesExistInAllColumns() Then
                    bEditColXVScroll_Busy = True

                    Dim iDestVerPos As Integer = 0

                    rtbEditColVScroll = CType(sender, RichTextBox)
                    Dim iVerPos As Integer = GetScrollPos(rtbEditColVScroll.Handle, SB_VERT)

                    iVerPos <<= 16
                    Dim wParam As UInteger = CUInt(SB_THUMBPOSITION) Or CUInt(iVerPos)

                    For n As Int16 = INAME_COL1 To LAST_DATA_COL_INDEX
                        With CType(Me.TableLayoutPanel1.Controls.Item(ColRtbNamePrefix & n), RichTextBox)
                            iDestVerPos = GetScrollPos(.Handle, SB_VERT)
                            If iVerPos <> iDestVerPos And rtbEditColVScroll.Name <> .Name Then
                                If (SetScrollPos(.Handle, SB_VERT, iVerPos, True) <> -1) Then
                                    SendMessage(.Handle, WM_VSCROLL, New IntPtr(wParam), New IntPtr(0))
                                    My.Application.DoEvents()
                                    My.Application.DoEvents()
                                Else
                                    Debug.Print("Can't set info (Err: " & GetLastWin32Error() & ")")
                                End If
                            End If
                        End With
                    Next

                    bEditColXVScroll_Busy = False
                End If
            End If
      End Sub

Open in new window


from what i can debug, my problems seem to be getting caused within the DoEvents() method, however hopefully someone more wiser can point me in the right direction.

any help would be appreciated.

cheers
gem56Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
Take a look at this previously asked question...

"Lock Scrolling on Multiple RichTextBoxes"
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_24810186.html

Wayne
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gem56Author Commented:
oh wow, thats perfect!

many thanks Wayne :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.