Previous topicNext topic
Help > 开发指南 > Excel > API > 示例 > Shape形状 >
如何:创建形状连接符

您可以使用连接线连接两个形状。此示例演示如何创建形状连接符、修改形状连接线以及将其两端附加到形状。


创建形状连接符

调用 ShapeCollection.AddConnector 方法以创建未绑定的形状连接符。

Vb.Net
Dim shapeConnector As DevExpress.Spreadsheet.Shape = worksheet.Shapes.AddConnector(DevExpress.Spreadsheet.ConnectorType.Curved, 10, 10, 500, 500)

C#
DevExpress.Spreadsheet.Shape shapeConnector = worksheet.Shapes.AddConnector(DevExpress.Spreadsheet.ConnectorType.Curved, 10, 10, 500, 500);

修改形状连接符

下表列出了用于更改连接器外观的 API。

任务 应用程序接口 说明
更改连接器的类型 ConnectorFormat.ConnectorType 连接器类型
更改连接器的颜色和厚度 ShapeFormatBase.Outline 大纲
ShapeOutline.Width 宽度
指定连接器起始的箭头选项 ArrowSettings.StartArrowheadType 起始箭头类型
ArrowSettings.StartArrowheadWidth 起始箭头宽度
ArrowSettings.StartArrowheadLength 起始箭头长度
指定连接器末端的箭头选项 ArrowSettings.EndArrowheadType 末端箭头类型
ArrowSettings.EndArrowheadWidth 末端箭头宽度
ArrowSettings.EndArrowheadLength 末端箭头长度

下面的代码示例演示如何使用这些成员使连接器看起来像下图所示。

Vb.Net
'更改连接器的颜色和厚度。
shapeConnector.Outline.SetSolidFill(Color.Black)
shapeConnector.Outline.Width = 2.5

'指定连接器末端的箭头选项。
Dim connectorFormat As DevExpress.Spreadsheet.ConnectorFormat = shapeConnector.ConnectorFormat
connectorFormat.Arrows.StartArrowheadType = DevExpress.Spreadsheet.ArrowheadType.Stealth
connectorFormat.Arrows.StartArrowheadWidth = DevExpress.Spreadsheet.ArrowheadSize.Large
connectorFormat.Arrows.StartArrowheadLength = DevExpress.Spreadsheet.ArrowheadSize.Small

connectorFormat.Arrows.EndArrowheadType = DevExpress.Spreadsheet.ArrowheadType.Stealth
connectorFormat.Arrows.EndArrowheadWidth = DevExpress.Spreadsheet.ArrowheadSize.Large
connectorFormat.Arrows.EndArrowheadLength = DevExpress.Spreadsheet.ArrowheadSize.Small

C#
// 更改连接器的颜色和厚度。
shapeConnector.Outline.SetSolidFill(Color.Black);
shapeConnector.Outline.Width = 2.5;

// 指定连接器末端的箭头选项。
DevExpress.Spreadsheet.ConnectorFormat connectorFormat = shapeConnector.ConnectorFormat;
connectorFormat.Arrows.StartArrowheadType = DevExpress.Spreadsheet.ArrowheadType.Stealth;
connectorFormat.Arrows.StartArrowheadWidth = DevExpress.Spreadsheet.ArrowheadSize.Large;
connectorFormat.Arrows.StartArrowheadLength = DevExpress.Spreadsheet.ArrowheadSize.Small;

connectorFormat.Arrows.EndArrowheadType = DevExpress.Spreadsheet.ArrowheadType.Stealth;
connectorFormat.Arrows.EndArrowheadWidth = DevExpress.Spreadsheet.ArrowheadSize.Large;
connectorFormat.Arrows.EndArrowheadLength = DevExpress.Spreadsheet.ArrowheadSize.Small;

将形状附加到连接线

以下方法允许您将形状链接到连接线。

检查 ShapeGeometry.ConnectionSiteCount 属性以检索形状的连接站点编号。每个形状的站点索引顺序都不同。通常,索引从顶部(0)开始,逆时针方向增长,如下图所示。

对于三维形状,连接点的索引变化如下。

代码示例演示如何将形状附加到连接器。连接线绑定到每个形状的第三个站点。

Vb.Net

 connectorFormat.ConnectStartPoint(shape1, 3)

connectorFormat.ConnectEndPoint(shape2, 3)

C#

 connectorFormat.ConnectStartPoint(shape1, 3);

connectorFormat.ConnectEndPoint(shape2, 3);

提示

调用ConnectorFormat.DisconnectStartPoint或者ConnectorFormat.DisconnectEndPoint方法,将连接线与形状分离。