I implemented an undoEngine in my custom form designer (using MSKB 2004
sample). But when I call GlobalInvoke(StandardCommands.Undo), the
menucommandservice cannot find the StandardCommands.Undo menucommand. I
found out that the StandardCommands.Undo was never added to my
menucommandservice. I know that the AddCommand only adds the
designer-supported commands, how should I instruct my form designer to add
the Undo/Redo standard commands?
Since the undo does not get added by default
(StandardCommands.Delete is as well as StandardCommands.AlignRight and
so on do get added by default.), so I added the command myself in the
MenuCommandService constructor with:
AddCommand(new MenuCommand(new EventHandler(OnUndo),
StandardCommands.Undo));
Also added the event handler code with:
private void OnUndo(object sender, EventArgs e)
{
//This is where I am hung up - what do I do here?
}
Any help would be greatly appreciated! Also please refer to the post:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=83654&SiteID=1
Thanks,
Alan
InK_ - 28 Feb 2006 08:22 GMT
Alan
I had a task to add SendToBack and BringToFront functionality to designer.
I've used the following approach:
1) I've added to the designerhost contructor these code:
//add global verbs
IMenuCommandService menuCommandService =
(IMenuCommandService)this.GetService(typeof(IMenuCommandService));
DesignerVerb verb = new DesignerVerb("Bring To Front", new
EventHandler(this.BringToFrontClickHandler), StandardCommands.BringToFront);
menuCommandService.AddVerb(verb);
verb = new DesignerVerb("Send To Back", new
EventHandler(this.SendToBackClickHandler), StandardCommands.SendToBack);
menuCommandService.AddVerb(verb);
2) Then add additional handlers:
private void BringToFrontClickHandler(object sender, EventArgs e)
{
IMenuCommandService menuCommandService =
(IMenuCommandService)this.GetService(typeof(IMenuCommandService));
menuCommandService.GlobalInvoke(StandardCommands.BringToFront);
}
private void SendToBackClickHandler(object sender, EventArgs e)
{
IMenuCommandService menuCommandService =
(IMenuCommandService)this.GetService(typeof(IMenuCommandService));
menuCommandService.GlobalInvoke(StandardCommands.SendToBack);
}
3) You should also add PopupMenu behavior to the class implementing
IMenuCommandService.
Hope it will help somehow.

Signature
Regards,
Inna Stetsyak aka InK_
> I implemented an undoEngine in my custom form designer (using MSKB 2004
> sample). But when I call GlobalInvoke(StandardCommands.Undo), the
[quoted text clipped - 25 lines]
> Thanks,
> Alan