Category / Section
Activate Pan tool in different mouse buttons
2 mins read
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