小编Qua*_*ang的帖子

如何在 Microsoft Office Word 中添加菜单项

我试图根据这篇文章在 Microsoft Word 中创建一个右键单击菜单项。

这是我的代码:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        try
        {
            eventHandler = new _CommandBarButtonEvents_ClickEventHandler(MyButton_Click);
            Word.Application applicationObject = Globals.ThisAddIn.Application as Word.Application;
            applicationObject.WindowBeforeRightClick += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowBeforeRightClickEventHandler(App_WindowBeforeRightClick);
        }
        catch (Exception exception)
        {
            MessageBox.Show("Error: " + exception.Message);
        }
    }

    void App_WindowBeforeRightClick(Microsoft.Office.Interop.Word.Selection Sel, ref bool Cancel)
    {
        try
        {
            this.AddItem();
        }
        catch (Exception exception)
        {
            MessageBox.Show("Error: " + exception.Message);
        }

    }
    private void AddItem()
    {
        Word.Application applicationObject = Globals.ThisAddIn.Application as Word.Application;
        CommandBarButton commandBarButton = applicationObject.CommandBars.FindControl(MsoControlType.msoControlButton, missing, "HELLO_TAG", missing) as …
Run Code Online (Sandbox Code Playgroud)

c# vsto ms-word

6
推荐指数
2
解决办法
3669
查看次数

标签 统计

c# ×1

ms-word ×1

vsto ×1