Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C语言中的visio insertlistmember#_C#_Visio - Fatal编程技术网

C# C语言中的visio insertlistmember#

C# C语言中的visio insertlistmember#,c#,visio,C#,Visio,有人知道如何在c#中使用visio insertListMember方法吗? 我尝试用以下命令执行该方法,但它给出了一个“运行时错误-需要424对象” 我还使用了dropIntoList方法,它工作得很好,但出于特定目的,我需要使用insertListMember方法。(确定列表的高度) 要获得形状,请执行以下操作: public Visio.Shape DropShape(string rectName, string masterShape) { //get

有人知道如何在c#中使用visio insertListMember方法吗?

我尝试用以下命令执行该方法,但它给出了一个“运行时错误-需要424对象” 我还使用了dropIntoList方法,它工作得很好,但出于特定目的,我需要使用insertListMember方法。(确定列表的高度)

要获得形状,请执行以下操作:

    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);
    }

从您的代码来看,“Drawer”看起来像某种Visio应用程序包装器,但本质上允许您将形状添加到页面上已经存在的列表中。下面是该方法的一个示例,如果您只想直接从模具中拖放,还可以选择此方法:

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中),应产生以下结果:


以防人们怀疑我最终修正了方法。但是,我认为,如果您使用的是visio Interop程序集v15,则不需要此方法。(我正在使用v14)

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
    }
}
    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);
    }