Visio二次开发(二)----Shape的添加和连接

     先说一说为什么我要用到Visio的二次开发,现在做的项目设计到了一些电子地图,下面的这张图片是美工画的一张地铁里面门禁布局图,而这些图在做项目的时候是需要用Visio画的,有提前画好的直接加载到项目中就可以使用,但是有些是需要通过代码也就是二次开发来实现的!
Visio二次开发(二)----Shape的添加和连接

     下面说说具体的实现过程:

     shape的添加

     你只需要找到相应的模板,模板下的形状,就可以加载形状,没有什么困难的,如果你实在不知道,那么就学者去用用Visio宏,对你的学习很有帮助(Visio二次开发(一)—-巧用Visio宏

'''新建一个documents集合'''
 Visio.Documents visDocs = adcVisio.Document.Application.Documents;
'''加载模板并将其加载到一个停靠的窗口中'''
 Visio.Document visStencil = visDocs.OpenEx("BASIC_M.VSS", (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);
'''加载一个当前活动的Page绘图区域'''
Visio.Page visPage = adcVisio.Document.Application.ActivePage;

'''加载三角形'''
Visio.Master visioRectMaster = visStencil.Masters.get_ItemU(@"Triangle");
Visio.Shape visioRectShape = visPage.Drop(visioRectMaster, 3.25, 4.5);
'''加载圆形'''
Visio.Master visioRect1Master = visStencil.Masters.get_ItemU(@"Square");
Visio.Shape visioRect1Shape = visPage.Drop(visioRect1Master, 1.25, 2.5);
'''加载动态链接线'''
Visio.Master visioWallMaster = visStencil.Masters.get_ItemU(@"Line-curve connector");
Visio.Shape visioWallShape = visPage.Drop(visioWallMaster, 5.5, 6.5);

     Shape的连接

     从上面的途中可以看出,两个门Shape之间有的是通过线连接的,那么我们能够通过代码来实现连接的功能吗?当然,必须的可以:

 ''' <summary>'''
 ''' 将两个形状进行连接'''
 ''' </summary>'''
 '''<param name="shape1"></param>'''
 ''' <param name="shape2"></param>'''
 ''' <param name="connector"></param>'''
 private static void ConnectShapes(Visio.Shape shape1, Visio.Shape shape2, Visio.Shape connector)
     {
        ''' get the cell from the source side of the connector '''
        Cell beginXCell = connector.get_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.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXFormOut,
                (short)Visio.VisCellIndices.visXFormPinX));
       ''' get the cell from the destination side of the connector'''
       Cell endXCell = connector.get_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.get_CellsSRC(
                (short)Visio.VisSectionIndices.visSectionObject,
                (short)Visio.VisRowIndices.visRowXFormOut,
                (short)Visio.VisCellIndices.visXFormPinX));
        }

     然后再在定义形状的代码下边加上一句话

'''将两个图形用动态链接线链接起来'''
ConnectShapes(visioRectShape, visioRect1Shape, visioWallShape);

     下面展示一下效果:

Visio二次开发(二)----Shape的添加和连接

上一篇:Kubernetes是Docker的终结者?我不认同!


下一篇:AgileEAS.NET平台开发实例-药店系统-报表开发(下)