Articles in this section

Activate Pan tool in different mouse buttons

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

 

Conclusion

I hope you enjoyed learning about activating the PanTool using different mouse buttons.

You can refer to WinForms Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Diagram example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied