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 メソッドは Type Mismatch Exception (-2147352571) をスローしています。任意のアイデアは、単語の右クリック メニューに項目を追加し、それが既に存在する場合は追加しないようにする正しい方法です ありがとう

4

1 に答える 1

1

パラメータrefとして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);
于 2009-05-15T06:51:42.803 に答える