|
How to implement Undo and redo operations in .NET -- YeshwanthHV --
Hi friends, I am trying to implement Undo and Redo Operations in C#.NET. Can anyone of you give me an idea how I can perform this ? Thanks in Advance, Yeshwanth |
|
-- BradleyPeter --
What do you want to undo and redo? An ASP.NET page? A Windows form? A single control in a Web page? A single control in a form? Groups of controls? What types of controls (e.g. do you want word-by-word undo/redo in a text control)? Peter |
|
-- YeshwanthHV --
Hello friends... How to perform Undo and redo operations in .NET. I am writing an application which helps to undo all the actions done and also to redo the operations. Can you ppl please give me an idea of how to implement these things in .NET Thanks, Yesh |
|
-- Yesh --
Hi Peter, I am writing an windows application in C#.NET. What I am trying to do is I am creating some graphical shapes on the form. let us assume that I draw a sqaure, a rectangle , a line on the form in the same order. So when I click Undo, at first line has to be disappear. Next when I click undo , rectangle has to disappear. In short , I need something where all the user actions can be saved and then retreive it when desired . I know that we can use stack and arraylist for this. But I am in need of some more information on this. Thanks, Yesh Bradley, Peter wrote: What do you want to undo and redo? An ASP.NET page? A Windows form? A single control in a Web page? A single control in a form? Groups of controls? What types of controls (e.g. do you want word-by-word undo/redo in a text control)? Peter |
|
-- BradleyPeter --
The most obvious strategy, I think, would be to "remember" the actions you take. You need to think very carefully about the construction of the object that represents your application's state. So, for example, if you are performing drawing operations on a surface, you would need a Surface class with a variable, or set of variables, that held operations performed on the surface in the order that they are performed - it'd look something like a stack, in fact. This isn't going to be easy because of the varying number of parameters that might be associated with each action. Maybe you'd have to store the operation as a string and parse it on an undo/redo. You've also got to have an equivalent reversal for each action. This may mean you have to store further data in your object. Maybe you need a set of pointers to functions (Hmmm) - that probably means delegates in .NET terms. You'll also have to maintain a pointer into your stack so that you can do multiple undos and redos, if that's what you want to do. I think I'd be tempted to solve the problem for one undo/redo before going on to perform arbitrary numbers of undos/redos. This might even suggest a recursive solution. Not a trivial problem - unless I'm over-complicating it. It'll be interesting to see what other people can come up with. It is a fault with me that I tend to miss easy solutions. HTH Peter |
|
-- Cerebrus --
No, I believe you're quite right, Peter. Undo / Redo is a functionality that can be simple or very complex depending on the nature of the actions performed. |
|
-- Cerebrus --
I suggest you read Peter's answer to the other similar thread doing the rounds. |
|
-- Sevinfooter --
I also agree. You will need to track the history for starters, and you will need to flag your actions somehow so that when you do an undo/redo, it is tagged with a way of determinning which direction to go with the event. for example, if you're last action was to delete, it should be flagged somehow so that your code knows it was "delete" and performs the opposite of delete. Personally, I would not rewrite the majority of this, as it has already been done countless times....reinventing the wheel and all that.... Check out this link, which shows how to use xml to handle your redo/undo stuff: http://www.informit.com/articles/article.asp?p=25047&rl=1 Cheers, Mark |