首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >连接列表中的visio形状

连接列表中的visio形状
EN

Stack Overflow用户
提问于 2018-09-24 13:47:47
回答 1查看 350关注 0票数 1

我试着用下面的代码连接几个形状:

代码语言:javascript
运行
复制
Visio.Master ConnectionMaster = _masters.get_ItemU(connectorShapeName);
Visio.Shape Connector = _activePage.Drop(ConnectionMaster, 1, 1);

// get the start cell of connector
var b1 = (short) Visio.VisSectionIndices.visSectionObject;
var b2 = (short) Visio.VisRowIndices.visRowXForm1D;
var b3 = (short) Visio.VisCellIndices.vis1DBeginX;
Visio.Cell beginXCell = Connector.get_CellsSRC(b1, b2, b3);

// and the end one
var e1 = (short) Visio.VisSectionIndices.visSectionObject;
var e2 = (short) Visio.VisRowIndices.visRowXForm1D;
var e3 = (short) Visio.VisCellIndices.vis1DEndX;
Visio.Cell endXCell = Connector.get_CellsSRC(e1, e2, e3);

// get start point from first shape
var bt1 = (short) Visio.VisSectionIndices.visSectionObject;
var bt2 = (short) Visio.VisRowIndices.visRowXFormOut;
var bt3 = (short) Visio.VisCellIndices.visXFormPinX;
var toBegin = fromShape.get_CellsSRC(bt1, bt2, bt3);

// get start point of second shape
var et1 = (short) Visio.VisSectionIndices.visSectionObject;
var et2 = (short) Visio.VisRowIndices.visRowXFormOut;
var et3 = (short) Visio.VisCellIndices.visXFormPinX;
var toEnd = toShape.get_CellsSRC(et1, et2, et3);

// connect 
beginXCell.GlueTo(toBegin);
endXCell.GlueTo(toEnd);

此代码适用于使用以下代码添加到visio文档中的形状:

代码语言:javascript
运行
复制
Visio.Master shapeToDrop = _masters.get_ItemU(name);
Visio.Shape shape = _activePage.Drop(shapeToDrop, x, y);

但是如果形状被放到文档中,然后添加到列表中,如下所示:

代码语言:javascript
运行
复制
var shape = _activePage.DropIntoList(shapeToDrop, target, position);

我收到错误:“发生了异常。”在此代码中:

代码语言:javascript
运行
复制
var toBegin = fromShape.get_CellsSRC(bt1, bt2, bt3);

那么,连接列表中的形状的正确方法是什么呢?我哪里做错了?

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2018-09-24 17:24:16

我怀疑您的问题与连接无关,而是与确保将项目放入列表时的类别匹配有关。这里有一个简短的示例来演示这个问题(从Visio中的一个空白绘图开始):

代码语言:javascript
运行
复制
void Main()
{
    //Run this code against a blank drawing in Visio
    var vApp = MyExtensions.GetRunningVisio();

    var vDoc = vApp.ActiveDocument;
    var stencilDoc = vDoc.Application.Documents.OpenEx("wfctrl_m.vssx",
                                                       (short)Visio.VisOpenSaveArgs.visOpenRO
                                                       + (short)Visio.VisOpenSaveArgs.visOpenDocked);
    var vPag = vApp.ActivePage;

    var diagramServices = vDoc.DiagramServicesEnabled;
    vDoc.DiagramServicesEnabled = (int)Visio.VisDiagramServices.visServiceVersion140 
                                + (int)Visio.VisDiagramServices.visServiceVersion150;
    var shpList = vPag.Drop(stencilDoc.Masters.ItemU["List box"], 2.25, 9.5);
    var itemMaster = stencilDoc.Masters.ItemU["List box item"];

    // Drop two items in - this works because the item
    // shapes have the correct required categories ('Grid')
    vPag.DropIntoList(itemMaster, shpList, 1);
    vPag.DropIntoList(itemMaster, shpList, 1);

    // Now set the list's required categories to someting else
    shpList.CellsU["User.msvSDListRequiredCategories"].FormulaU = $"\"Bob\"";

    // Note an error is thrown here because the list item being
    // inserted does not contain the category 'Bob'
    try
    {           
        vPag.DropIntoList(itemMaster, shpList, 1);
    }
    catch (COMException ex) when (ex.ErrorCode == -2032465763)
    {
        //Inappropriate source object for this action.
        Console.WriteLine($"{ex.Message} - check matching categories in List and ListItem shapes");
    }

    vDoc.DiagramServicesEnabled = diagramServices;
}

您可能应该编写一个快速检查,检查在item形状中读取User.msvShapeCategories单元格的位置,然后检查它们是否属于列表形状(User.msvSDListRequiredCategories)中所需的类别。有关更多详细信息,请参阅本文的“控制容器成员资格”部分:Custom Containers, Lists and Callouts in Visio 2010

只是补充一下,如果你想连接列表中的形状,那么你可以使用上面的方法,或者类似这样的方法,这取决于你想要的控制级别:

代码语言:javascript
运行
复制
var item = vPag.DropIntoList(itemMaster, shpList, 1);
var target = vPag.DrawRectangle(4, 9, 6, 7.5);
item.AutoConnect(target, Visio.VisAutoConnectDir.visAutoConnectDirNone);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52473320

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档