禁用Visio C#中的重叠形状

时间:2018-07-26 16:28:23

标签: c# visual-studio visio overlapping

我将形状放到Visio页面/文档上的某个区域中,具体取决于它们的x,y值。一些形状包含相似的x和y坐标,因此彼此重叠。有没有一种方法可以自动防止形状在页面上重叠?还是可以放置一个方程式以将形状移动特定数量的英寸,以确保形状不再重叠?以下是我到目前为止已实现的代码。

        var vApp = new Visio.Application();
        Visio.Document vDoc, vStencil;
        Visio.Page vPage;
        Visio.Shape vToShape, vFromShape, vConnector;
        Visio.Master vConnectorMaster, vFlowChartMaster;
        double dblXLocation;
        double dblYLocation;
        Visio.Cell vBeginCell, vEndCell;
        int iCount;
        string TEMPLATEPATH = @"C:\temp\Test\testtemplate.vsdx";

        //Change this constant to match your choice of location and file name.
        string SAVENEWFILE = @"C:\temp\test\testfile.vsdx";

        //open the template without any open parameters
        vDoc = vApp.Documents.Open(TEMPLATEPATH);

        vPage = vApp.ActivePage;
        //now, load a Stencil containing basic flowchart shapes
        vStencil = vApp.Documents.Open(@"C:\temp\test\teststencil.vssx");
        vFlowChartMaster = vStencil.Masters[1];

        for (iCount = 0; iCount < xValues.Length; iCount++)
        {

            vFlowChartMaster = vStencil.Masters[aryValues[0, 0]];
            dblXLocation = getXLocation(xValues[iCount]);
            dblYLocation = getYLocation(yValues[iCount]);
            vToShape = vPage.Drop(vFlowChartMaster,
               dblXLocation, dblYLocation);
            vToShape.Text = names[iCount];
            vToShape.TextStyle.ToLower();



            vFromShape = vToShape;
            vToShape = null;



        }

        vDoc.Pages[1].Name = "Graph";
        try
        {
            //Delete the previous version of the file.
            File.Delete(SAVENEWFILE);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }


        vDoc.SaveAs(SAVENEWFILE);
        vDoc.Close();
        vApp.Quit();
        vDoc = null;
        vApp = null;
        GC.Collect();

附加的here是放置在图上重叠的前三个形状。将有大约70多个要绘制的形状分布在整个图形上,并且有些重叠。

1 个答案:

答案 0 :(得分:0)

至少在手动放置形状时,以下2个标志有助于避免重叠。 在代码中尝试一下,可能会起作用。

Application.ActiveWindow.Shape.CellsSRC(visSectionObject, visRowMisc, visLOFlags).FormulaU = "1"
Application.ActiveWindow.Shape.CellsSRC(visSectionObject, visRowShapeLayout, visSLOPlowCode).FormulaU = "2"