Hello everyone.

I had a previous thread about Undo/Redo, but couldn't find it. Anyway, to the point:

I use the following code to save and load the states of a RichTextBox control:
Code:
   Public Structure FieldState
        Sub New(ByVal control As RichTextBox)
            Me.SelectionStart = control.SelectionStart
            Me.SelectionLength = control.SelectionLength
            Me.Data = control.Rtf
            Dim s As New SCROLLINFO(SCROLLINFO.Mask.Position)
            SCROLLINFO.GetScrollInfo(control.Handle, SCROLLINFO.Bar.Horizontal, s)
            Me.ScrollPosX = s.nPos
            SCROLLINFO.GetScrollInfo(control.Handle, SCROLLINFO.Bar.Vertical, s)
            Me.ScrollPosY = s.nPos
        End Sub

        Public Sub Apply(ByVal control As RichTextBox)
            control.Rtf = Me.Data
            control.Select(Me.SelectionStart, Me.SelectionLength)
            Dim s As New SCROLLINFO(SCROLLINFO.Mask.Position)
            s.nPos = Me.ScrollPosX
            SCROLLINFO.SetScrollInfo(control.Handle, SCROLLINFO.Bar.Horizontal, s, True)
            s.nPos = Me.ScrollPosY
            SCROLLINFO.SetScrollInfo(control.Handle, SCROLLINFO.Bar.Vertical, s, True)
            'control.Invalidate()
        End Sub

        Public SelectionStart As Integer
        Public SelectionLength As Integer
        Public Data As String
        Public ScrollPosX As Integer
        Public ScrollPosY As Integer

        Private Structure SCROLLINFO
            Public Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As IntPtr, ByVal fnBar As Bar, ByRef lpScrollInfo As SCROLLINFO) As Boolean
            Public Declare Function SetScrollInfo Lib "user32" (ByVal hWnd As IntPtr, ByVal fnBar As Bar, ByRef lpScrollInfo As SCROLLINFO, ByVal redraw As Boolean) As Integer
            Sub New(ByVal mask As Mask)
                Me.cbSize = Runtime.InteropServices.Marshal.SizeOf(Me)
                Me.fMask = mask
            End Sub
            Private cbSize As UInteger
            Private fMask As Mask
            Public nMin As Integer
            Public nMax As Integer
            Public nPage As UInteger
            Public nPos As Integer
            Public nTrackPos As Integer
            Public Enum Bar As Integer
                Horizontal = 0
                Vertical = 1
                Client = 2
                Both = 3
            End Enum
            Public Enum Mask As UInteger
                Range = &H1
                Page = &H2
                Position = &H4
                DisableNoScroll = &H8
                TrackPosition = &H10
                ALL = Range Or Page Or Position Or TrackPosition
            End Enum
        End Structure
    End Structure
Usage:
Code:
Dim s As New FieldState(RichTextBox1)
s.Apply(RichTextBox1)
This works almost 100% right, but there is one problem: the textbox does not update the scroll states. The scrollbars visibly change, but contents don't. Also, when you click the up/down buttons on the Scrollbar, it jumps to a different position and moves from there. So, how can I make that scroll information go through to the textbox control?