.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links


Posted By:      Posted Date: October 08, 2010    Points: 0   Category :Windows Application
how do i implement undo/redo features in C#

View Complete Post

More Related Resource Links

BIDS undo/redo buttons

In MS Visual Studio 2008 on Windows Server 2008 or BIDS my undo / redo buttons are grayed out when I am editing an SSIS package. I would like to know if there is a way to enable this. I have searched and searched everything looks retardedly complicated to get this working. Help? Anyone, anyone... Microsoft are you there?

Problem implementing Undo/redo functionality in an UML editor

Ok so I will try to make this short.
I am implementing undo/redo functionality in an UML diagram editor. I have objects of classes, all implementing my VisualUMLComponent interface.
I have a class, VisualUMLCollection, implementing ObservableCollection<VisualUMLComponent> to keep track of all objects (classes, interfaces, arrows, comments, abstracts, etc) to draw on my Canvas object. This works fine.

Now to the point.
I try to implement undo/redo, with having each object having a pointer to a PreviousState and NextState of type VisualUMLComponent. As such, when I change an object, I can first Clone() it, and insert it at the proper place in the doubly linked list.
I have made class for the undo/redo functionality. It has two stacks undoStack and redoStack of type Stack<DiagramChange>. DiagramChange class represents changes in the diagram. It can have three types: Add, Remove and Alter, for when adding an object, removing an object, or changing an object respectively.

My problem is with the code below, that I get an ArgumentOutOfRangeException    at System.Windows.Media.VisualCollection.Insert(Int32 index, Visual visual), when I try to .Add an old state object to my VisualUMLCollection:


How to Implement Undo and Redo in c#



    I have a picture box in my page..i am drawing some graphics like circle ,ellipse and arrow on the picture box in the picturebox_mouseup event .I need to undo or redo the drawing that i have drawn on the picture box after clicking undo or redo button..i don't know how to implement this in my page..Can you please help me with code...Here is my code in the picturebox mouse_up event..

  private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
            blnDrawing = false;
            blnErasing = false;
            a =e.X;
              if (circle == 1 || text == 1 || ellipse == 1 || arrow == 1)


how to create undo / redo function into my form

Im new to VB but have a strong aptitude for code and with a bit of guidence I can usally get it done. Is this function tought to get working?

how to create undo / redo function into my form

I posted this in the wrong area sorry for that..
Im new to VB but have a strong aptitude for code and with a bit of guidence I can usally get it done. Is this function tought to get working?

Team System: Work Items and Undo Support


Add support for work items to the Team Foundation Server version control add-in.

Brian A. Randell

MSDN Magazine September 2007

{ End Bracket }: To Confirm is Useless, to Undo Divine


The common user interface technique of confirmation, popping a dialog box into the user's face and asking, "Are you really REALLY sure you want to do that?" is evil. It's unfriendly, it's distracting, and it's completely ineffective.

David S. Platt

MSDN Magazine March 2005

Disable VS2005 Undo?


Does anyone know if there is a way to disable the Undo feature within VS2005?  I searched through the options but nothing jumped out at me.


Error connecting to undo manager of source file?

When I run my project I get an error that says: Error connecting to undo manager of source file: path to my project/myproject/contact.aspx.designer.cs".How do I correct this?

How to undo any change done on checked tree view control

Frnds,   I have Check boxed tree view control on a popup control.   Two button also there, 1) Save   2) Cancel.   On cancel I am hiding the pop-up control. But if any change I have mad on tree view (Check or Uncheck) will be there if I am open it again.    So I need to undo any change done on tree view if I clicked cancel button.     Can any one help me on this?

Undo After Adding Activity Which Causes Designer Resize

Hi, I created a very simple test application which consists of a Toolbox and a Workflow Designer.  In the toolbox, I only added a "Terminate" activity: public MainWindow() { InitializeComponent(); new System.Activities.Core.Presentation.DesignerMetadata().Register(); _workflowDesigner = new WorkflowDesigner(); Grid.SetColumn(_workflowDesigner.View, 1); _workflowDesigner.Load(new System.Activities.Statements.Flowchart()); LayoutGrid.Children.Add(_workflowDesigner.View); _toolbox = new ToolboxControl(); ToolboxCategory undoTestCategory= new ToolboxCategory("Undo Test"); ToolboxItemWrapper terminateTool = new ToolboxItemWrapper(typeof(System.Activities.Statements.TerminateWorkflow), "Terminate"); undoTestCategory.Add(terminateTool); _toolbox.Categories.Add(undoTestCategory); Grid.SetColumn(_toolbox, 0); LayoutGrid.Children.Add(_toolbox); } When I drag/drop the "Terminate" to the middle of the designer, I can press Ctrl-Z once to undo it (i.e. remove it from the designer).  However, if I drop it at the edge of the designer which forces a resize/expansion of the designer, it takes 4 Ctrl-Zs to undo it.  Is there a way around this?  Also, is there an easy way in the debugger to see the undo stack? Thank you.  

Advance Search Box undo All Sites

I am using search center for our advance searches and have enabled the scope picker.  I have listed several scopes and one is called “All Sites”.  How can undo all other checks when “All Sites” is checked?

Thanks in advance for your help.

Is there a way to undo/remove/delete an active directory user profile syncronization? [SP 2010]


I successfully managed to synchronize the active directory with Sharepoint 2010.  Unfortunately, the farm I was on has different FQDN /Netbios domain names.  So all ~1000 user profiles are now imported with the wrong domain, and the subsequent errors one would expect.


Is there a way to get back to a blank slate?  technet has an article on "resetting" profile synchronization (http://technet.microsoft.com/en-us/library/ff681014.aspx), but that requires being able to verify the GUID of the user profile synchronization database, which I am also unaware of how to do.


Please help, and thank you in advance.

InvalidOperationException in SynchronizationContextSwitcher.Undo


I can't repro this on my machine, but on a customers machine my app throws the following exception:



The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone).


   at System.Threading.SynchronizationContextSwitcher.Undo()

   at System.Threading.ExecutionContextSwitcher.Undo()

   at System.Threading.ExecutionContext.runFinallyCode(Object userData, Boolean exceptionThrown)

Accidentally deleted webpart, need to get it back or redo page (tried to add page, but rich text box


I just need to get the web part back! I accidentally deleted it! Please help!


If there is no way to do this, I could start over. I tried to add a new web part but the "Rich Text Box" isn't showing up in the "Content Query Web Part" box.



error connecting to undo manager of source file


this keeps popping up intermittantly, and i have not been able to find a reason on these forums or the web as to why this happens.

the error keeps referring to a designer.cs file.

does anyone have any remedies for this?

 i am using vs2005 team edition with sp1, running a vs2003  .net 1.1 project that has been converted to vs2005 .net 2.0 (version  v2.0.50727)


The Undo operation encountered a context that is different...

This is not specific enough information for me to know what I did wrong and where. Does anyone have any insight to this? It appears to have something to do with asynchronous socket I/O completion.

System.Transactions Critical: 0 :
<TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical">
<Description>Unhandled exception</Description>
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend