简体   繁体   English

MS Word插件,添加一个在右键单击所选文本时弹出的按钮

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

I am working on a shared addin for MS Word 2007. I would like to add a button which pops up when selected text is right clicked. 我正在为MS Word 2007共享共享插件。我想添加一个按钮,当右键单击所选文本时会弹出。 The attached snapshot should make this clear. 随附的快照应清楚说明这一点。

Currently, the user has to select the text and then click a button on a custom control. 当前,用户必须选择文本,然后单击自定义控件上的按钮。 It would be a lot easier if after selecting the text, s/he could right click it and press the relevant button in the popup. 如果在选择文本之后,他/他可以右键单击它并按下弹出窗口中的相关按钮,将会容易得多。

替代文字

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 使用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#): 万一正常菜单没问题,您可以使用这种方式(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 ;) 您可以使用VSTO来做到这一点,我不确定它是否与共享的Add-In技术完全相同,但是也许确实有帮助;)

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 - MSDN-

You cannot modify the Mini toolbar programmatically. 您不能以编程方式修改Mini工具栏。

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. http://groups.google.com/group/microsoft.public.word.docmanagement/browse_thread/thread/cf55d996b3f51a06/65b2bad22e2a3583?lnk=st&q=Remove+Items+from+Word+2007是在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). 使用COM和创建一个单词加载项非常相似(尽管我没有尝试过),基本上,您需要找到上下文菜单控件并向其中添加一个项(您的功能)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM