Retrieve Connection point names of a Visio shape in C#
I am working with Microsoft Visio 2007 and Visual C#. I have a stencil with some shapes. Each connection point of each master shape in the stencil has got a name. How can I get these names in C#?
I need a way to distinguish connection points of a shape and I thought assign a name to each connection point was the easiest one.
P.S. I assigned the name to the connection points in the so called "ShapeShe开发者_Go百科et" of the master shape, i.e. the same place where one can see the coordinates of the connection points.
The following example uses Cell Indices to loop through all the X cells in the Connection Point row. The RowName property is used to get the name of each row in the section.
Visio.Shape shape = // get the shape
List<string> listOfNames = new List<string>();
// Loop through all the connection point rows in the shape.
short iRow = (short) Visio.VisRowIndices.visRowConnectionPts;
while (shape.get_RowExists(
(short) Visio.VisSectionIndices.visSectionConnectionPts,
iRow,
(short) 0) != 0)
{
// Get a cell from the connection point row.
Visio.Cell cell = shape.get_CellsSRC(
(short) Visio.VisSectionIndices.visSectionConnectionPts,
iRow,
(short) Visio.VisCellIndices.visCnnctX);
// Ask the cell what row it is in.
listOfNames.Add(cell.RowName);
// Next row.
++iRow;
}
Given a Shape object you can get the X Cell of a connection point row using the Cells property. If you are using the PIA you can make a call like this:
Visio.Shape shape ; // get the shape
Visio.Cell cell = shape.get_Cells("Connections.MyName.X");
From this Cell object you can access the rest of the Connection point Row.
If you are using different localized versions of Visio, or you are planning to localize your application, you should investigate the difference between Cells and CellsU.
精彩评论