2016-03-14 42 views
1

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

我試圖用下面的命令來執行的方法,但它提供了一個 「所需的運行時錯誤 - 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); 
    } 

回答

1

從您的代碼,「抽屜」看起來是某種Visio中的應用程序包裝的,但本質上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專業版),並且會導致如下:

enter image description here

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