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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Activate Pan tool in different mouse buttons

Platform: WinForms |
Control: Diagram

Activating PanTool while clicking the different mouse button

The requirement of activating the PanTool while clicking different mouse buttons can be achieved by creating the custom PanTool by inheriting the PanTool class and override the ProcessMouseDown method in custom class.

The below code snippet shows how to create the custom pan tool:


//Creating CustomPanTool class
class CustomPanTool : Syncfusion.Windows.Forms.Diagram.PanTool
    //Assigning tool name
    internal static string toolName = "CustomPanTool";
    public CustomPanTool(Syncfusion.Windows.Forms.Diagram.DiagramController src)
    : base(src)
       this.Name = toolName;
    //Overriding ProcessMouseDown 
    public override Syncfusion.Windows.Forms.Diagram.Tool ProcessMouseDown(System.Windows.Forms.MouseEventArgs evtArgs)
       if (evtArgs.Button == System.Windows.Forms.MouseButtons.Middle)
          this.InAction = true;
          this.ViewOrigin = this.Controller.Viewer.Origin;
          return this;
          return null;


‘Creating Custom PanTool class
 Friend Class CustomPanTool
  Inherits Syncfusion.Windows.Forms.Diagram.PanTool
                       ‘Assigning tool name
  Friend Shared toolName As String = "CustomPanTool"
 Public Sub New(ByVal src As Syncfusion.Windows.Forms.Diagram.DiagramController)
 Me.Name = toolName
            End Sub
 'Overriding ProcessMouseDown 
 Public Overrides Function ProcessMouseDown(ByVal evtArgs As System.Windows.Forms.MouseEventArgs) As Syncfusion.Windows.Forms.Diagram.Tool
             If evtArgs.Button = System.Windows.Forms.MouseButtons.Middle Then
               Me.InAction = True
               Me.ViewOrigin = Me.Controller.Viewer.Origin    
                                     Return Me
                          Return Nothing
             End If
 End Function
End Class


After creating the CustomTool it is mandatory to register the tool.

The below code snippet shows how to register a custom control


//initializing the custom tool
CustomPanTool tool = new CustomPanTool(diagram1.Controller);
//Registering the tool



' initializing the custom tool
Dim tool As New CustomPanTool(diagram1.Controller)
'Registering the tool


The below code snippet shows how to activate the tool when mouse middle button is clicked.


void diagram1_MouseClick(object sender, MouseEventArgs e)
        if (e.Button == System.Windows.Forms.MouseButtons.Middle)
              //Activating the custom Tool



Private Sub diagram1_MouseClick(ByVal sender As Object, ByVal e As MouseEventArgs)
 If e.Button = System.Windows.Forms.MouseButtons.Middle Then
  'Activating the custom Tool
 End If
End Sub



2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
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

Live Chat Icon For mobile