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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I customize the behavior of a user interface tool?

Platform: WinForms |
Control: Diagram |
Published Date: April 30, 2011 |
Last Revised Date: June 4, 2019

How do I customize the behavior of a user interface tool?

User interface tools may be customized by either subclassing and overriding the behavior of a base tool, or by implementing a new Tool type that derives from the Syncfusion.Windows.Forms.Diagram.Tool base class, and is modeled after an existing Tool type.

The following code shows the outline of a new symbol insert tool that is modeled after the standard Syncfusion.Windows.Forms.Diagram.SymbolInsertTool. The custom insert tool differs from the base tool by displaying a message box instead of the BoundaryConstraintsException when the insertion point violates the boundary, and lets you re-insert the symbol at a new location.

C#

/// Custom InsertSymbolTool that displays a message when the symbol insertion point violates the
/// diagram's boundary constraints.
public class MyInsertSymbolTool : Tool, IMouseEventReceiver
{
public MyInsertSymbolTool() : base("MyInsertSymbolTool")
{
}
public MyInsertSymbolTool(string name) : base(name)
{
}
public MyInsertSymbolTool(string name, System.Type symbolType) : base(name)
{
this.symbolType = symbolType;
}
/// Called when the tool is activated.
protected override void OnActivate()
{
...
}
/// Called when the tool is deactivated.
protected override void OnDeactivate()
{
...
}
/// Called when a mouse down event occurs.
void IMouseEventReceiver.MouseDown(System.Windows.Forms.MouseEventArgs e)
{
...
}
/// Called when a mouse move event occurs.
void IMouseEventReceiver.MouseMove(System.Windows.Forms.MouseEventArgs e)
{
...
}
/// Called when a mouse up event occurs.
void IMouseEventReceiver.MouseUp(System.Windows.Forms.MouseEventArgs e)
{
...
}
}

To replace an existing Tool with the new Tool type, you will have to first use the Syncfusion.Windows.Forms.Diagram.Controller.UnRegisterTool(Tool tool) method to unregister the previously registered default Tool, and then use the Controller.RegisterTool(...) method to register your newly defined Tool.

C#

// Check whether the standard InsertSymbolTool is registered with the Controller, and
// unregister the tool it if present.
Tool[] regtools = this.diagramComponent.Controller.GetAllTools();
foreach(Tool regtool in regtools)
{
if(regtool.Name == "InsertSymbolTool")
{
this.diagramComponent.Controller.UnRegisterTool(regtool);
break;
}
}
// Register the custom insert symbol tool
this.diagramComponent.Controller.RegisterTool(new MyInsertSymbolTool());

 

VB

' Check whether the standard InsertSymbolTool is registered with the Controller, and
' unregister it if present.
Dim regtools() As Tool = Me.diagramComponent.Controller.GetAllTools()
Dim regtool As Tool
For Each regtool In regtools
If regtool.Name = "InsertSymbolTool" Then
Me.diagramComponent.Controller.UnRegisterTool(regtool)
End If
Next
' Register the custom insert symbol tool
Me.diagramComponent.Controller.RegisterTool(New MyInsertSymbolTool)

The attached file contains the full C# and VB source code for the MyInsertSymbolTool class. The definitions for the standard tools that ship with Essential Diagram can be found under the 'Essential Studio\...\Base\Diagram.Base\Src\Tools\' folder. Referring to these classes will give a better idea on to how to go about implementing your custom tools.

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

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

Up arrow icon

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