)
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

Activate Pan tool in different mouse buttons

Platform: WinForms |
Control: Diagram |
Published Date: November 25, 2015 |
Last Revised Date: June 2, 2019

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:

[C#]

//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)
       {
          base.ProcessMouseDown(evtArgs);
          this.InAction = true;
          this.ViewOrigin = this.Controller.Viewer.Origin;
          return this;
       }
       else
          return null;
       }
    }
}

[VB]

‘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)
 MyBase.New(src)
 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
                          MyBase.ProcessMouseDown(evtArgs)
               Me.InAction = True
               Me.ViewOrigin = Me.Controller.Viewer.Origin    
                                     Return Me
             Else
                          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

[C#]

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

 

[VB]

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

 

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

[C#]

void diagram1_MouseClick(object sender, MouseEventArgs e)
{
        if (e.Button == System.Windows.Forms.MouseButtons.Middle)
        {
              //Activating the custom Tool
             diagram1.Controller.ActivateTool("CustomPanTool");
       }
}

 

[VB]

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
  diagram1.Controller.ActivateTool("CustomPanTool")
 End If
End Sub

 

 

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

Live Chat Icon For mobile
Live Chat Icon