|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
Note: This is an unedited contribution. If this article is inappropriate,
needs attention or copies someone else's work without reference then please
Report This Article
Introduction
Many .Net component verndor requires to add global context menu command to Visual Studio, which should be available whenever a required Background
When I was developing my winforms layout manager Called 'SmartLayouts', I had exactly this requirement. I required it because I needed to provide ease of use to my users for layouting task. A toolbutton, Menu Command could do it, but it looks hassle in long term to users. After several days of intense research I found the trick of creating global verb which stays in Context Menu of desired The MethodFor Adding the Verb, you first need to ensure that correct ISelectionService sel = host.RootComponent.Site.GetService(typeof(ISelectionService)) as ISelectionService;
IMenuCommandService mcs = host.RootComponent.Site.GetService(typeof(IMenuCommandService)) as IMenuCommandService;
if (!mcs.Verbs.Contains(verb))
{
mcs.Verbs.Add(verb);
}
Source CodeThe source code of sample project is given. However, you need to add theContextMenuCommand.Addin in your addin folder(usually in My Documents\Visual Studio 2005\Addins) and edit its xml node <assembly> to point to real ContextMenuCommand.dll. <Assembly>C:\Documents and Settings\vkhaitan\My Documents\Visual Studio 2005\Projects\ContextMenuCommand\ContextMenuCommand\bin\ContextMenuCommand.dll</Assembly>All the Documents and Source code are supplied with license The Code Project Open License (CPOL). ConclusionIt would have been better, if .Net framework provided method for this and we didn't need to resort to these hacks. However, in practice, I found that this hack works flawlessly and never shown me any kind of problem or bug. So you can use it whenever you need it.
|
||||||||||||||||||||||