We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

custom tool

Thread ID:





12152 Mar 23,2004 11:30 AM UTC Nov 9,2004 01:16 AM UTC WinForms 8
Tags: Diagram
Wes Hunter
Asked On March 23, 2004 11:30 AM UTC

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.

Administrator [Syncfusion]
Replied On March 24, 2004 01:38 PM UTC

Hi Wes, 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\\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. Prakash Syncfusion

Carl Gilbert
Replied On June 14, 2004 04:57 PM UTC

Hi, Was there any news on that sample of creating a custom tool? thanks

Administrator [Syncfusion]
Replied On June 16, 2004 04:15 PM UTC

Sample provided in Forum post - http://www.syncfusion.com/Support/forums/message.aspx?MessageID=15203.

Truman Lackey
Replied On November 5, 2004 09:21 PM UTC

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?

Arun Srinivasan [Syncfusion]
Replied On November 7, 2004 09:55 PM UTC

Hi Truman, 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; return link; } //Create and Register the Link Tool for the custom link Tool linkTool = this.diagram1.Controller.GetTool("LinkTool"); ((LinkTool)linkTool).LinkFactory = new LinkFactory(this.CreateLink); this.diagram1.Controller.RegisterTool(linkTool); //Activate Link Tool this.diagram1.ActivateTool("LinkTool"); Regards Arun

Administrator [Syncfusion]
Replied On November 8, 2004 03:26 PM UTC

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. Thanks, Truman

Administrator [Syncfusion]
Replied On November 8, 2004 04:45 PM UTC

I followed the instructions on how to create a custom tool from a post above and came up with this: Public Class DEPortTool Inherits Tool Implements IClickEventReceiver, IMouseEventReceiver Public Sub New(ByVal name As String) MyBase.New(name) End Sub Public Overridable Overloads Sub DoubleClick() Implements IClickEventReceiver.DoubleClick End Sub Public Overridable Overloads Sub Click() Implements IClickEventReceiver.Click End Sub 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.Nodes.Add(port) insCmd.Location = New PointF(e.X, e.Y) Me.Controller.ExecuteCommand(insCmd) End If Me.Controller.DeactivateTool(Me) End If End Sub Public Overridable Overloads Sub MouseDown(ByVal e As MouseEventArgs) Implements IMouseEventReceiver.MouseDown End Sub Public Overridable Overloads Sub MouseMove(ByVal e As MouseEventArgs) Implements IMouseEventReceiver.MouseMove End Sub Protected Overrides Sub OnActivate() ''change to cursor Me.Controller.Cursor = Cursors.Cross End Sub End Class Just to help me in being correct in the implementatation are there any changes that you would make in the code?

Arun Srinivasan [Syncfusion]
Replied On November 9, 2004 01:16 AM UTC

Hi Truman 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: //Register MyPortTool MyPortTool myporttool = new MyPortTool("InsertMyPort"); this.diagram1.Controller.RegisterTool(myporttool); You can insert this custom port in the Diagram by clicking Add MyPort button: //Activate MyPortTool MyPortTool myporttool = this.diagram1.Controller.GetTool("InsertMyPort") as MyPortTool; this.diagram1.Controller.ActivateTool(myporttool); I hope this sample will help you do what you are seeking. Regards Arun


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon