Results 1 to 9 of 9

Thread: [RESOLVED] Infinite undo/redo: how do you implement it?

Threaded View

  1. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: Infinite undo/redo: how do you implement it?

    <post cleared, time for final result>

    Got it all working very nicely, but it took some workaround:
    vb Code:
    1. Public Class ScrollData
    2.         Sub New(ByVal control As Control, ByVal scroll As Bar, Optional ByVal flags As Mask = Mask.ALL)
    3.             Me.SetData(control.Handle, scroll, flags)
    4.         End Sub
    5.         Sub New(ByVal handle As IntPtr, ByVal scroll As Bar, Optional ByVal flags As Mask = Mask.ALL)
    6.             Me.SetData(handle, scroll, flags)
    7.         End Sub
    8.         Public Sub SetData(ByVal handle As IntPtr, ByVal scroll As Bar, Optional ByVal flags As Mask = Mask.ALL)
    9.             Me.flags = flags
    10.             Dim s As New SCROLLINFO(Me.flags)
    11.             SCROLLINFO.GetScrollInfo(handle, scroll, s)
    12.             Me.handle = handle
    13.             Me.scroll = scroll
    14.             Me.Minimum = s.nMin
    15.             Me.Maximum = s.nMax
    16.             Me.Position = s.nPos
    17.             Me.Page = s.nPage
    18.             Me.TrackPosition = s.nTrackPos
    19.         End Sub
    20.         Public flags As mask
    21.         Public handle As IntPtr
    22.         Public scroll As Bar
    23.         Public Minimum As Integer
    24.         Public Maximum As Integer
    25.         Public Page As UInteger
    26.         Public Position As Integer
    27.         Public TrackPosition As Integer
    28.         Public Function Update(Optional ByVal redraw As Boolean = True) As Integer
    29.             Dim s As New SCROLLINFO(Me.flags)
    30.             s.nMin = Me.Minimum
    31.             s.nMax = Me.Maximum
    32.             s.nPos = Me.Position
    33.             s.nPage = Me.Page
    34.             s.nTrackPos = Me.TrackPosition
    35.             Return SCROLLINFO.SetScrollInfo(Me.handle, Me.scroll, s, redraw)
    36.         End Function
    37.         Public Enum Bar As Integer
    38.             Horizontal = 0
    39.             Vertical = 1
    40.             Client = 2
    41.             Both = 3
    42.         End Enum
    43.         Public Enum Mask As UInteger
    44.             Range = &H1
    45.             Page = &H2
    46.             Position = &H4
    47.             DisableNoScroll = &H8
    48.             TrackPosition = &H10
    49.             ALL = Range Or Page Or Position Or TrackPosition
    50.         End Enum
    51.         Private Structure SCROLLINFO
    52.             Public Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As IntPtr, ByVal fnBar As Bar, ByRef lpScrollInfo As SCROLLINFO) As Boolean
    53.             Public Declare Function SetScrollInfo Lib "user32" (ByVal hWnd As IntPtr, ByVal fnBar As Bar, ByRef lpScrollInfo As SCROLLINFO, ByVal redraw As Boolean) As Integer
    54.             Sub New(ByVal mask As Mask)
    55.                 Me.cbSize = Marshal.SizeOf(Me)
    56.                 Me.fMask = mask
    57.             End Sub
    58.             Private cbSize As UInteger
    59.             Private fMask As Mask
    60.             Public nMin As Integer
    61.             Public nMax As Integer
    62.             Public nPage As UInteger
    63.             Public nPos As Integer
    64.             Public nTrackPos As Integer
    65.         End Structure
    66.     End Class

    Usage:
    Code:
            Dim s As New ScrollData(TextBox1, ScrollData.Bar.Vertical)
            s.Position += 1
            s.Update()
    Added the API structure inside a class so I was able to hold the scroll type loaded and the Handle of it, since passing the arguments all the time is a bit useless.

    Thanks all, especially Paul for reviving the ScrollInfo idea and for the previous examples.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width