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

发布于 2024-07-16 00:51:37 字数 218 浏览 17 评论 0原文

我正在为 MS Word 2007 开发一个共享插件。我想添加一个在右键单击所选文本时弹出的按钮。 随附的快照应该可以清楚地说明这一点。

目前,用户必须选择文本,然后单击自定义控件上的按钮。 如果选择文本后,他/她可以右键单击它并按弹出窗口中的相关按钮,那就容易多了。

替代文字

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

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ゝ杯具 2024-07-23 00:51:37

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

使用 Word 的共享插件

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

祝你好运! :)

编辑:

它必须是功能区样式上下文菜单还是普通上下文菜单中的按钮就足够了?
如果普通菜单没问题,您可以使用这种方式(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 来做到这一点,我不太确定它是否与共享插件技术的工作方式完全相同,但也许确实如此帮助 ;)

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 ;)

淡淡の花香 2024-07-23 00:51:37

来自 MSDN -

您无法以编程方式修改迷你工具栏。

医生的一半多一点。 在迷你工具栏上搜索。

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

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.

画骨成沙 2024-07-23 00:51:37

以下是如何做到这一点......

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);
}

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文