Results 1 to 9 of 9

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

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

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

    Hello everyone.

    I did this before, but it was really REALLY (really) messy and all it did was basically add and remove text and selection information from a stack. Result: When using Undo/Redo the selection got messed up, the text moved, sometimes causing lag of epic proportions. I need a way of having complete and smooth undo/redo class for storing all information I would possible need.

    How to know whether or not to add an undo stack is easy, I just checked if the user clicked in the text or moved using the arrow keys. As soon a previous marking was given for "next text change needs to be backed up", it was backed up. At that point I stored the RTF and selection start/length.

    Up to the question. What do I have to store of a RichTextbox control to be able to restore it to a previous state, and how can I reset it back to a previous state? See it as having a "RichTextBoxState" class:
    Code:
    Public Class RichTextBoxState
        Sub New(ByVal RTB As RichTextBox)
            Me.text = RTB.RTF
            Me.selectionstart = RTB.SelectionStart
            Me.selectionlength = RTB.SelectionLength
            '???
        End Sub
        Public text As String
        Public selectionstart As Integer
        Public selectionlength As Integer
        Public ??? As ???
        Public Sub Restore(ByVal RTB As RichTextBox)
            RTB.RTF = text
            RTB.Select(selectionstart, selectionlength)
            '???
        End Sub
    End Class
    After restoring it must display the EXACT same thing as when it was saved as a state.

    Any help greatly appreciated.

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