Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / February 2006

Tip: Looking for answers? Try searching our database.

How to add StandardCommands.Undo/Redo to MenuCommandService?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alan - 27 Feb 2006 03:08 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.