MS Word插件,添加右键单击所选文本时弹出的按钮
-
22-08-2019 - |
题
我正在为 MS Word 2007 开发一个共享插件。我想添加一个按钮,右键单击所选文本时会弹出该按钮。随附的快照应该可以清楚地说明这一点。
目前,用户必须选择文本,然后单击自定义控件上的按钮。如果选择文本后,他/她可以右键单击它并按弹出窗口中的相关按钮,那就容易多了。
解决方案 2
下面是如何可以做到这一点...
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);
}
其他提示
您需要延长正确的文本菜单。下面的链接中的话(无源代码)描述了如何可以做到这一点:
也许这链接可能会有点帮助与编码。我还没有尝试过了自己,但它可能指向到正确的方向。
祝你好运! :)
修改强>
它必须是带式上下文菜单或将正常的上下文菜单内的按钮足够? 如果正常的菜单将是确定的,你可能会用这样的方式(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;
您可以使用VSTO做到这一点,我不太知道,如果它的工作原理完全与共享加载项技术以同样的方式,但也许它确实帮助;)
从 MSDN -
您不能修改浮动工具栏程序。
略超过一半,该文档。搜索迷你工具栏上。
编辑: 您在图圆圈上面不会出现在右键单击弹出,它出现在亮点。上下文菜单(选定文本下方)可以让你自定义的功能,而不是小工具栏中的
http://groups.google.com/group/microsoft.public.word.docmanagement/browse_thread/thread/cf55d996b3f51a06/65b2bad22e2a3583?lnk=st&q=从+Word+2007 中删除+Items+ 是如何在 VBA 中做到这一点。它与使用 COM 非常相似,并且可能创建一个单词加载项(虽然我还没有尝试过),您基本上需要找到上下文菜单控件并向其添加一个项目(您的函数)。
不隶属于 StackOverflow