C#中的visio insertlistmember

时间:2016-03-14 02:58:01

标签: c# visio

有谁知道如何在c#中使用visio insertListMember方法(如下)? https://msdn.microsoft.com/en-us/library/office/ff768115.aspx

我尝试使用以下命令执行该方法,但它提供了"运行时错误-424对象所需" 我也使用了dropIntoList方法,它工作正常,但出于特定目的,我需要使用insertListMember方法。 (确定列表的高度)

    static void Main(string[] args)
    {
        //create the object that will do the drawing
        visioDrawing.VisioDrawer Drawer = new visioDrawing.VisioDrawer();
        Drawer.setUpVisio();

        Visio.Shape testShape;
        Visio.Shape testShape1;


        testShape = Drawer.DropShape("abc", "lvl1Box");
        testShape1 = Drawer.DropShape("ccc", "Capability");
        Drawer.insertListMember(testShape, testShape1, 1);
     }


   public void insertListMember(Visio.Shape outerlist, Visio.Shape innerShape, int position)
    {   
        ActiveDoc.ExecuteLine(outerlist + ".ContainerProperties.InsertListMember" + innerShape + "," + position);
    }

获得形状:

    public Visio.Shape DropShape(string rectName, string masterShape)
    {
        //get the shape to drop from the masters collection
        Visio.Master shapetodrop = GetMaster(stencilPath, masterShape);
        // drop a shape on the page
        Visio.Shape DropShape = acPage.Drop(shapetodrop, 1, 1);
        //put name in the shape
        Visio.Shape selShape = selectShp(DropShape.ID);
        selShape.Text = rectName;
        return DropShape;
    } 

    private Visio.Master GetMaster(string stencilName, string mastername)
    {
        // open the page holding the masters collection so we can use it
        MasterDoc = MastersDocuments.OpenEx(stencilName, (short)Visio.VisOpenSaveArgs.visOpenDocked);
        // now get a masters collection to use 
        Masters = MasterDoc.Masters;
        return Masters.get_ItemU(mastername);
    }

2 个答案:

答案 0 :(得分:1)

从您的代码中,'抽屉'看起来是某种Visio app包装器,但基本上InsertListMember允许您将形状添加到页面上已存在的列表中。如果您只是想直接从模板中删除,那么这是方法的示例和备选Page.DropIntoList

void Main()
{
    // 'GetRunningVisio' as per
    // http://visualsignals.typepad.co.uk/vislog/2015/12/getting-started-with-c-in-linqpad-with-visio.html
    // but all you need is a reference to the app
    var vApp = MyExtensions.GetRunningVisio();

    var vDoc = vApp.Documents.Add("wfdgm_m.vstx");
    var vPag = vDoc.Pages[1];
    var vCtrlsStencil = vApp.Documents["WFCTRL_M.VSSX"];
    var vListMst = vCtrlsStencil?.Masters["List box"];
    if (vListMst != null)
    {
        var vListShp = vPag.Drop(vListMst, 2, 6);
        var vListItemMst = vCtrlsStencil.Masters["List box item"];

        var insertPosition = vListShp.ContainerProperties.GetListMembers().Length - 1;

        //Use InsertListMember method
        var firstListItem = vPag.Drop(vListItemMst, 4, 6);
        vListShp.ContainerProperties.InsertListMember(firstListItem, insertPosition);
        firstListItem.CellsU["FillForegnd"].FormulaU = "3"; //Green

        //or use DropIntoList method on Page instead
        var secondListItem = vPag.DropIntoList(vListItemMst, vListShp, insertPosition);
        secondListItem.CellsU["FillForegnd"].FormulaU = "2"; //Red
    }
}

这是使用线框图模板(在Visio Professional中),应该产生以下结果:

enter image description here

答案 1 :(得分:0)

如果有人想知道我最终修复了这个方法。但是,我相信如果您使用的是visio Interop程序集v15,则不需要此方法。 (我正在使用v14)

    public void insertListMember(int outerShpID, int innerShpID, int position)
    {
        acWindow.DeselectAll();
        Visio.Page page = acWindow.Page;
        acWindow.Select(page.Shapes.get_ItemFromID(innerShpID), (short)Microsoft.Office.Interop.Visio.VisSelectArgs.visSelect);
        Debug.WriteLine("Application.ActivePage.Shapes.ItemFromID(" + outerShpID + ").ContainerProperties.InsertListMember ActiveWindow.Selection," + position);
        ActiveDoc.ExecuteLine("Application.ActivePage.Shapes.ItemFromID(" + outerShpID + ").ContainerProperties.InsertListMember ActiveWindow.Selection," + position);
    }