首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MS Word插件,添加右键单击所选文本时弹出的按钮

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

Stack Overflow用户
提问于 2009-03-26 03:43:12
回答 4查看 7.6K关注 0票数 1

我正在为MS Word 2007开发一个共享插件。我想添加一个按钮,当选定的文本被右击时弹出。连接的快照应该清楚地说明这一点。

目前,用户必须选择文本,然后单击自定义控件上的按钮。如果在选择文本后,用户可以右键单击该文本并在弹出窗口中按下相关按钮,则会容易得多。

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2009-04-06 21:39:37

下面是如何做到这一点的……

代码语言:javascript
复制
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);
}
票数 1
EN

Stack Overflow用户

发布于 2009-03-31 08:38:28

您需要扩展正确的上下文菜单。下面的链接用文字(无源代码)描述了如何实现这一点:

Shared Addin using Word

也许这个Link可能会对编码有一点帮助。我自己还没有尝试过,但它可能会指向正确的方向。

祝你好运!:)

编辑:

它是否必须是功能区样式的上下文菜单,或者普通上下文菜单中的一个按钮就足够了?如果正常菜单没有问题,您可以使用这种方式(C#):

代码语言:javascript
复制
 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;

你可以用VSTO做到这一点,我不太确定它是否与共享插件技术完全一样,但也许它确实有帮助;)

票数 2
EN

Stack Overflow用户

发布于 2009-04-03 22:18:47

来自MSDN -

您不能以编程方式修改小工具栏。

在医生的一半多一点的地方。在小工具栏上搜索。

编辑:您在上图中圈出的弹出窗口不会在右键单击时出现,而是在突出显示时出现。上下文菜单(位于选定文本下方)可以具有自定义功能,但不在小工具栏中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/684438

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档