Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..

I want to implement undo/redo option in windows app. I create one panel control inside that adding and deleting controls at run time, so need to implement undo/redo according to added or deleted control. If i delete any control then by undo operation it should recreate. If anyone have any idea please share.
Thanks in advance.

What I have tried:

I tried some code but it works for controls state, not for add and delete control from parent.
Posted
Updated 27-Jul-16 23:53pm
Comments
BillWoodruff 28-Jul-16 8:32am    
Without knowing more about what you do with the run-time controls, I don't think we can really help you.

How are the create controls used ? Are they hooked up to Events ?
SachinSutar 1-Aug-16 4:19am    
yes, attaching some mouse event to control after creation for resize and move controls within parent.
Ramza360 28-Jul-16 12:02pm    
Try the momento pattern.
SachinSutar 2-Aug-16 2:21am    
i tried momento pattern but it not work for add and remove controls.

1 solution

For deletion you can maintain a flag in the table to mark it as deleted and upon undo, you can reset the flag to reappear the record again. But for all this to happend you have to create another table which logs the recent required changes and accordingly you can revert the changes. You can workout for Update and Insert too. This could be the simplest approach to do this.

Haven't tried to do this ever so I agree there could be better approaches available and soon we may see some good suggestions/solutions.

In the meantime, you may check following article if it is relevant to your problem-
Multilevel Undo and Redo Implementation in C# - Part I (Using Single Object Representing Change Approach)[^]

Hope, it helps :)
 
Share this answer
 
Comments
SachinSutar 28-Jul-16 5:59am    
it looks something relevant, will try. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900