CommandBars.FindControl 抛出异常

发布于 2024-07-10 13:11:26 字数 1091 浏览 6 评论 0原文

我正在尝试使用 VSTO Word 插件中 CommandBars 对象的 FindControl 方法来获取命令栏对象还有什么 代码如下

 private void WireContextMenu(string MenuID,string Tag, string ID, ref Office.CommandBarButton Control)
    {
        try
        {
            object missing = System.Type.Missing;

            Control = (Office.CommandBarButton)this.Application.CommandBars[MenuID].FindControl((object)Office.MsoControlType.msoControlButton, ID, Tag, missing, missing);
            if (Control == null)
            {
                Control = (Office.CommandBarButton)this.Application.CommandBars[MenuID].Controls.Add(Office.MsoControlType.msoControlButton, ID, missing, missing, missing);
                Control.Caption = "Biolit Markup Selection";
                Control.Tag = Tag;
            }

            Control.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.cb_Click);
        }
        catch (Exception Ex)
        {
        }
    }

FindControl 方法抛出类型不匹配异常(-2147352571) 有任何想法吗 无论如何,这是将项目添加到Word的右键单击菜单中,然后确保如果它已经存在则不添加它的正确方法吗 谢谢

I am trying to use the FindControl Method of the CommandBars object in a VSTO Word addin to get what else a command bar object
Code is as follows

 private void WireContextMenu(string MenuID,string Tag, string ID, ref Office.CommandBarButton Control)
    {
        try
        {
            object missing = System.Type.Missing;

            Control = (Office.CommandBarButton)this.Application.CommandBars[MenuID].FindControl((object)Office.MsoControlType.msoControlButton, ID, Tag, missing, missing);
            if (Control == null)
            {
                Control = (Office.CommandBarButton)this.Application.CommandBars[MenuID].Controls.Add(Office.MsoControlType.msoControlButton, ID, missing, missing, missing);
                Control.Caption = "Biolit Markup Selection";
                Control.Tag = Tag;
            }

            Control.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.cb_Click);
        }
        catch (Exception Ex)
        {
        }
    }

The FindControl method is throwing a Type Mismatch Exception (-2147352571)
Any ideas
is this the right way anyhow to add a item to the right click menu of word and then make sure you dont add it if it already exists
Thanks

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

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

发布评论

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

评论(1

过去的过去 2024-07-17 13:11:26

您正在使用 Missing,其中 Missing 不允许作为参数
参考:链接文本
http://msdn.microsoft.com/en-us/ Library/system.type.missing.aspx

使用如下代码:

        object type = MsoControlType.msoControlPopup;
        object id = 1;
        object tag = null;
        object visible = 1;
        object recusive = false;
        //object missing = System.Type.Missing;

        CommandBarControl barControl = popParent.FindControl(type, id, tag, visible, recusive);

you are using Missing where Missing is not allowed as parameter
ref: link text
http://msdn.microsoft.com/en-us/library/system.type.missing.aspx

use code like this:

        object type = MsoControlType.msoControlPopup;
        object id = 1;
        object tag = null;
        object visible = 1;
        object recusive = false;
        //object missing = System.Type.Missing;

        CommandBarControl barControl = popParent.FindControl(type, id, tag, visible, recusive);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文