Is there any documentation or example illustrating how to create a custom tool? I need to create a tool that is similar to the link tool, but links together three diagram components instead of two. I have been unable to find any help in the docs or web site.
ADAdministrator Syncfusion Team March 24, 2004 08:38 AM
Unfortunately, we do not have any documentation/samples on creating a custom tool. But thanks for highlighting this shortcoming. The following steps should serve as a guideline for creating a custom tool.
1. The custom tool should be a derivative of the Syncfusion.Windows.Forms.Diagram.Tool class. Give it a default constructor that passes a default name to the base constructor.
2. Decide what events you want to receive from the controller and implement the correct interface(s) such as IMouseEventReceiver or IClickEventReceiver.
3. Determine if the tool requires exclusive access to the controller when it is activated. By default, tools are exclusive. The only tool currently implemented that is not exclusive is the SelectTool. It can be active while other tools are active.
4. Process the events received and have the tool maintain any state it needs in order to perform the action or command. Typically, when a tool is finished with its task it creates and executes a command by calling Controller.ExecuteCommand. Then it deactivates itself by calling Controller.DeactivateTool.
5. Make sure to test the Tool.Enabled and Tool.Active flags in the appropriate places when you receive events. Tools operate on a cooperative principle, so just because a tool gets an event does not mean it should act on it. If it is not Active, then it’s likely that some other tool is Active in Exclusive mode and you want your tool to avoid colliding with it.
6. When you want the tool to deactivate itself, make sure you do it through the controller by calling Controller.DeactivateTool. Likewise, when you activate a tool make sure it is done through Controller.ActivateTool. This will ensure that other tools get the proper notifications.
If you have the source code version of Essential Diagram, you can also refer to the pre-built Tools in the ''..\Syncfusion\Essential Suite\18.104.22.168\Diagram\Src\Tools\'' folder.
I hope this helps. I will go ahead and make this into an Essential Diagram KB article(will try to add a sample as well) for future reference.
CGCarl GilbertJune 14, 2004 11:57 AM
Was there any news on that sample of creating a custom tool?
ADAdministrator Syncfusion Team June 16, 2004 11:15 AM
Sample provided in Forum post - http://www.syncfusion.com/Support/forums/message.aspx?MessageID=15203.
TLTruman LackeyNovember 5, 2004 04:21 PM
I am trying to create custom tools based on LinkTool and PortTool that will insert a custom link or port. I have looked at the custom rectangle example but I do not see a compareable function to OnRectangleComplete for these tools. I want to insert on a diagram a custom link or custom port that contains some custom properties. Will you post an example on how to create a custom link tool that inserts a custom link?
ASArun Srinivasan Syncfusion Team November 7, 2004 04:55 PM
Here is a code snippet that demonstrates how you can create, register and use a custom LinkTool:
//Custom Link: Red, DashDot line, Arrow at end
protected Link CreateLink(PointF pts)
Link link = new Link(Link.Shapes.Line, pts);
link.EndPoints.LastEndPointDecorator = new EndPointDecorator(EndPointVisuals.ClosedArrow);
link.LineStyle.LineColor = Color.Red;
link.LineStyle.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
//Create and Register the Link Tool for the custom link
Tool linkTool = this.diagram1.Controller.GetTool("LinkTool");
((LinkTool)linkTool).LinkFactory = new LinkFactory(this.CreateLink);
//Activate Link Tool
ADAdministrator Syncfusion Team November 8, 2004 10:26 AM
Thanks for the help but now I am stumped on how to make a custom port tool. It does not have a portfactory or anything that I can see of that nature or any event that I can use.
ADAdministrator Syncfusion Team November 8, 2004 11:45 AM
I followed the instructions on how to create a custom tool from a post above and came up with this:
Public Class DEPortTool
Implements IClickEventReceiver, IMouseEventReceiver
Public Sub New(ByVal name As String)
Public Overridable Overloads Sub DoubleClick() Implements IClickEventReceiver.DoubleClick
Public Overridable Overloads Sub Click() Implements IClickEventReceiver.Click
Public Overridable Overloads Sub MouseUp(ByVal e As MouseEventArgs) Implements IMouseEventReceiver.MouseUp
'' insert a DEPort at the mouseup position
If Me.Enabled And Me.Active Then
If e.Button = MouseButtons.Left Then
Dim port As New DECirclePort()
Dim insCmd As New InsertNodesCmd()
insCmd.Location = New PointF(e.X, e.Y)
Public Overridable Overloads Sub MouseDown(ByVal e As MouseEventArgs) Implements IMouseEventReceiver.MouseDown
Public Overridable Overloads Sub MouseMove(ByVal e As MouseEventArgs) Implements IMouseEventReceiver.MouseMove
Protected Overrides Sub OnActivate()
''change to cursor
Me.Controller.Cursor = Cursors.Cross
Just to help me in being correct in the implementatation are there any changes that you would make in the code?
ASArun Srinivasan Syncfusion Team November 8, 2004 08:16 PM
Here is sample that uses a Custom PortTool, which inserts a port that is red in color. The custom PortTool is implemented in MyPortTool.cs.
The custom PortTool is registered in the Form1''s constructor:
MyPortTool myporttool = new MyPortTool("InsertMyPort");
You can insert this custom port in the Diagram by clicking Add MyPort button:
MyPortTool myporttool = this.diagram1.Controller.GetTool("InsertMyPort") as MyPortTool;
I hope this sample will help you do what you are seeking.