0

我正在以编程方式在 visio 中绘制 UML 图,其中我使用动态连接器来连接形状。但是在某些情况下,连接器穿过形状而不是穿过页面(即连接器从源形状到目标形状的路径通过位于源和目标之间的另一个形状),我希望连接器应该只通过页面。请建议如何使这成为可能。

4

1 回答 1

1

您必须从 C# 进行翻译,但这就是我的做法:

/// <summary>Attaches two Visio shapes to each other with the specified connector object.</summary>
/// <param name="shape1">Visio shape to connect from.</param>
/// <param name="shape2">Visio shape to connect to.</param>
/// <param name="connector">Visio line shape that will connect shape1 to shape2.</param>
/// <param name="straight">Whether this connector should be a straight line</param>
[CLSCompliant(false)]
protected static void ConnectShapes(
    Visio.Shape shape1,
    Visio.Shape shape2,
    Visio.Shape connector,
    bool straight = false)
    {
        try
        {
            // get the cell from the source side of the connector
            Visio.Cell beginXCell = connector.CellsSRC[(short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXForm1D, (short)Visio.VisCellIndices.vis1DBeginX];

            // glue the source side of the connector to the first shape
            beginXCell.GlueTo(shape1.CellsSRC[(short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX]);

            // get the cell from the destination side of the connector
            Visio.Cell endXCell = connector.CellsSRC[(short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXForm1D, (short)Visio.VisCellIndices.vis1DEndX];

            // glue the destination side of the connector to the second shape
            endXCell.GlueTo(shape2.CellsSRC[(short)Visio.VisSectionIndices.visSectionObject, (short)Visio.VisRowIndices.visRowXFormOut, (short)Visio.VisCellIndices.visXFormPinX]);

            if (straight)
            {
                connector.CellsU["ConLineRouteExt"].ResultIUForce = (double)Visio.VisCellVals.visLORouteExtStraight;
                connector.CellsU["ShapeRouteStyle"].ResultIUForce = (double)Visio.VisCellVals.visLORouteCenterToCenter;
            }
            else
            {
                // THIS IS WHAT YOU ARE LOOKING FOR
                connector.CellsU["ConLineRouteExt"].ResultIUForce = (double)Visio.VisCellVals.visLORouteExtNURBS;
                connector.CellsU["ShapeRouteStyle"].ResultIUForce = (double)Visio.VisCellVals.visLORouteRightAngle;
            }
        }
        catch (Exception e)
        {
            throw (e);
        }
    }
于 2013-05-10T17:06:42.600 回答