Search code examples
c#visio

Microsoft.Office.Interop.Visio + AutoConnect + Arrow


I would like to know if there is a way to use AutoConnect from Microsoft.Office.Interop.Visio to connect two Shape and make it like the link between both have an arrow from the first to the second Shape.

If it is not possible to make this connection using AutoConnect, would you know another way to make the arrow connection to the two Shape?

The method I am trying to use is as follows:

private void Connect Drawings (IVisio.Shape shape1, IVisio.Shape shape2, IVisio.VisAutoConnectDir dir)
{
     shape1.AutoConnect (shape2, dir);
}

Visio Print


Solution

  • Thanks for clarifiying in the comments. The reason the arrow head isn't displaying is probably because the page has a 'No theme' theme set and the default for connectors under this scheme is not to show arrow heads. So you can either start off with a template or drawing with the desired theme set, or, set it in code as part of your drop.

    Here's an example (using LINQPad):

    void Main()
    {
        var vApp = MyExtensions.GetRunningVisio();
        var vPag = vApp.ActivePage;
        var shp1 = vPag.DrawRectangle(2,5,3,4.5);
        var shp2 = vPag.DrawRectangle(4,7,5,6.5);
        shp1.AutoConnect(shp2, Visio.VisAutoConnectDir.visAutoConnectDirRight);
        //Assuming 'No theme' is set for the page, no arrow will 
        //be shown so change theme to see connector arrow
        vPag.SetTheme("Office Theme");
    }
    

    If you're interested in some 'theme' related background reading I have a few posts on the subject starting with this one: http://visualsignals.typepad.co.uk/vislog/2013/04/using-themes-in-visio-2013.html