Articles in this section

How to extend the Link types present in the Diagram in WinForms?

To create a new Link class or to customize the drawing for an existing link type, implement a subclass of 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 return 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;
}

 

Conclusion

I hope you enjoyed learning about how to extend the Link types present in the Diagram in WinForms.

You can refer to WinForms Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Diagram example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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