By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,243 Members | 1,654 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,243 IT Pros & Developers. It's quick & easy.

Undo,Redo functionalities for Designer host not working

P: 19
Hi All,

I want to perform basic Edit menu functionalities on my custom design surface.
While all the Cut/Copy/Paste/Deelete/Select functionalities working fine with code below,Undo/Redo standard commands are not working for me.

Expand|Select|Wrap|Line Numbers
  1. IMenuCommandService menusrv= HostControl.HostSurface.GetService(typeof(IMenuCommandService)) as IMenuCommandService;
  2.              if (menusrv != null)
  3.              {
  4.                  switch (editstring)
  5.                  {
  6. ////////////////////////////////////////////
  7. //Undo/Redo not working    ////
  8. //////////////////////////////////////////
  9.                      case "Undo/Redo":
  10.                        menusrv.GlobalInvoke(StandardCommands.undo/StandardCommands.Redo)
  11. break;
  12.  
  13.                       case "Cut":
  14.                          menusrv.GlobalInvoke(StandardCommands.Cut);
  15.                          break;
  16.                      case "Copy":
  17.                          menusrv.GlobalInvoke(StandardCommands.Copy);
  18.                          break;
  19.                      case "Paste":
  20.                          menusrv.GlobalInvoke(StandardCommands.Paste);
  21.                          break;
  22.                      case "Delete":
  23.                          menusrv.GlobalInvoke(StandardCommands.Delete);
  24.                          break;
  25.                      case "SelectAll":
  26.                          menusrv.GlobalInvoke(StandardCommands.SelectAll);
  27.                          break;
  28. }
  29. }
It will be of great help if sumbody can share a piece of code to implement Undo/Redo functionalitis.

I am using .NET 2003,C#
Help will be much appreciated!

Thanks and Regards,
-Anupam Roy
Feb 13 '08 #1
Share this Question
Share on Google+
1 Reply


kenobewan
Expert 2.5K+
P: 4,871
This example may help:

Undo and redo commands in the constructor

Expand|Select|Wrap|Line Numbers
  1. AddCommand(new MenuCommand(new EventHandler(this.ExecuteUndo), StandardCommands.Undo));
  2.  
  3. AddCommand(new MenuCommand(new EventHandler(this.ExecuteRedo), StandardCommands.Redo));
  4.  
  5. void ExecuteUndo(object sender, EventArgs e)
  6.  
  7. {
  8.  
  9. UndoEngineImpl undoEngine = _host.GetService(typeof(UndoEngine)) as UndoEngineImpl;
  10.  
  11. if (undoEngine != null)
  12.  
  13. undoEngine.DoUndo();
  14.  
  15. }
  16.  
  17. void ExecuteRedo(object sender, EventArgs e)
  18.  
  19. {
  20.  
  21. UndoEngineImpl undoEngine = _host.GetService(typeof(UndoEngine)) as UndoEngineImpl;
  22.  
  23. if (undoEngine != null)
  24.  
  25. undoEngine.DoRedo();
  26.  
Feb 13 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.