代码之家  ›  专栏  ›  技术社区  ›  Nikhil

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

  •  1
  • Nikhil  · 技术社区  · 16 年前

    我正在为MS Word 2007开发一个共享的加载项。我想添加一个按钮,当选中的文本被右键单击时弹出。所附的快照应清楚说明这一点。

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

    alt text

    4 回复  |  直到 9 年前
        1
  •  2
  •   Marcus    16 年前

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

    Shared Addin using Word

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

    祝你好运!:)

    编辑:

    它必须是功能区样式上下文菜单还是普通上下文菜单中的按钮足够? 如果正常菜单可以,您可以这样使用(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来实现这一点,我不太确定它是否与共享外接程序技术完全相同,但可能确实有帮助;)

        2
  •  2
  •   Chris    12 年前

    这是如何做到的……

    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);
    }
    
        3
  •  1
  •   Brandon    16 年前

    MSDN -

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

    医生那边有点多。在小工具栏上搜索。

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

        4
  •  0
  •   jle    16 年前

    http://groups.google.com/group/microsoft.public.word.docmanagement/browse_thread/thread/cf55d996b3f51a06/65b2bad22e2a3583?lnk=st&q=Removing+Items+from+Word+2007 是如何在VBA中执行的。它与使用COM非常相似,可能创建了一个单词外接程序(但我没有尝试过),您基本上需要找到上下文菜单控件并向其添加一个项(您的函数)。