MS Word Plugin, Adding a button which pops up on right click on selected text

倾然丶 夕夏残阳落幕 提交于 2019-12-04 19:48:32

You need to extend the correct contextmenu. The following link describes in words (no source code) how this can be achieved:

Shared Addin using Word

Maybe this Link might help a little with the coding. I haven't tried it out myself, but it might point into the right direction.

Good luck! :)

Edit:

Does it have to be the ribbon style context menu or would a button within the normal context menu be enough? In case the normal menu would be ok, you might use this way (C#):

 Microsoft.Office.Core.CommandBar cb = this.Application.CommandBars["Text"];

 Office.CommandBarControl newButton = cb.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);  
 newButton.Caption = "Test";
 newButton.Visible = true;
 newButton.Enabled = true;

You can do this with VSTO, I'm not so sure if it works exactly the same way with the shared Add-In technology, but maybe it does help ;)

Nikhil

Here is how this can be done...

Microsoft.Office.Core.CommandBar cellbar = diff.CommandBars["Text"];
Microsoft.Office.Core.CommandBarButton button = (Microsoft.Office.Core.CommandBarButton)cellbar.FindControl(Microsoft.Office.Core.MsoControlType.msoControlButton, 0, "MYRIGHTCLICKMENU", Missing.Value, Missing.Value);
if (button == null)
{
   // add the button
   button = (Microsoft.Office.Core.CommandBarButton)cellbar.Controls.Add(Microsoft.Office.Core.MsoControlType.msoControlButton, Missing.Value, Missing.Value, cellbar.Controls.Count + 1, true);
   button.Caption = "My Right Click Menu Item";
   button.BeginGroup = true;
   button.Tag = "MYRIGHTCLICKMENU";
   button.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(MyButton_Click);
}

From MSDN -

You cannot modify the Mini toolbar programmatically.

a little over halfway down the doc. Search on mini toolbar.

Edit: The popup you have circled in the image above doesn't appear on right-click, it appears on highlight. The context menu (below the selected text) could have your custom functionality, but not in the mini toolbar.

http://groups.google.com/group/microsoft.public.word.docmanagement/browse_thread/thread/cf55d996b3f51a06/65b2bad22e2a3583?lnk=st&q=Removing+Items+from+Word+2007 is how to do it in VBA. It is very similar using COM and probably creating a word add-in (I have not tried it though) You basically need to find the context menu control and add an item to it (your function).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!