undo and redo
how undo and redo,cut paste can be implemented in c#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
anamika agrawalPosted Feb 11, 2008, 4:26 AM
Mike GoldPosted Feb 8, 2008, 6:35 PM
if you are using an edit control, this is already built into the TextBox control (for example).
But your question needs to be much more specific to answer it. For example, what are you pasting text? images? What are you undoing, what kind of actions? insertion of text? database insertions? remote calls across the internet?
What sort of depth do you need for undo redo? Single undo? Single redo? Multiple undo/redo?
undo and redo is tricky. The easiest way I've seen is to build a stack (you can use the stack collection) of states of your program. Then push each state of your program on the stack using some "checkpoint" in your code. When the user hits undo pop the state of the program from the stack. The tricky part is of course how do you save the state of your program. If it's a drawing, then you can save the drawing (for example). If the state of your program can be maintained using code structures of some kind, then you can put these on the stack.