Articles in this section
Category / Section

How do I extend the Link types present in Essential Diagram?

1 min read

How do I extend the Link types present in Essential Diagram?

To create a new Link class or to customize the drawing for an existing link type, implement a subclass of the Syncfusion.Windows.Forms.Diagram.Link class with an appropriate override of the Link.CreateLinkShape(Link.Shapes shapeType, PointF[] pts) method. The CreateLinkShape method is called by the Link constructor and it is up to your override to suitably interpret the method parameters and returns a valid implementation of the Syncfusion.Windows.Forms.Diagram.IPoints interface. A sample override is shown below:

C#

// A subclass of the Syncfusion.Windows.Forms.Diagram.Link class
public class CustomLink : Syncfusion.Windows.Forms.Diagram.Link
{
// Override the Link.CreateLinkShape method to create a link for the specified type 
// and with the given points
protected override IPoints CreateLinkShape(Link.Shapes shapeType, PointF[] pts)
{
Shape linkShape = null;
  if(shapeType == Link.Shapes.OrthogonalLine)
   {
    OrthogonalLine orthogonalLine = new OrthogonalLine();
    orthogonalLine.AutomaticHeadings = true;
    linkShape = orthogonalLine;
   }
   if(linkShape != null)
   {
    linkShape.SetPoints(pts);
   }
   return linkShape;
}
}

 

Now all that is required to use this Link type is to provide to the LinkTool a LinkFactory delegate that instantiates this newly defined Link type when the tool is activated. A sample implementation is shown below:

C#

// Create a Link tool for the custom link type
LinkTool customLinkTool = new LinkTool("CustomLinkTool");
customLinkTool.LinkFactory = new LinkFactory(this.CreateCustomLink);
// Register this tool with the Diagram Controller
this.diagram.Controller.RegisterTool(customLinkTool);
// LinkFactory delegate for instantiating the CustomLink
protected Link CreateCustomLink(PointF[] pts)
{
CustomLink mylink = new CustomLink(Link.Shapes.OrthogonalLine, pts);
return mylink;
}

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied