Articles in this section

Customizing the PanTool to restricting Pan operation in Grey area instead of Model area

To restrict the pan operation in the grey area instead of the model area.

In the Diagram control, we can restrict the pan operation in the grey area instead of the model area. This can be achieved by customizing the Diagram’s “PanTool” class. From the customized class, override the ProcessMouseMove and ProcessMouseUp methods to update the “Origin” logically based on the model area.

Here is the code example for restricting the pan operation in grey area instead of model area.

[C#]

private PointF UpdateOrigin(int xOffset, int yOffset)
{
    double magnification = this.Controller.Viewer.Magnification / 100d;
    double offsetX = this.StartPoint.X - xOffset;
    double offsetY = this.StartPoint.Y - yOffset;

    offsetX = offsetX / magnification + this.ViewOrigin.X;
    offsetY = offsetY / magnification + this.ViewOrigin.Y;

    // Prevent negative values
    if (offsetX < 0)
        offsetX = 0;
    if (offsetY < 0)
        offsetY = 0;

    // Prevent x position while offsetX is going outside of the model
    if (this.Controller.Model.Size.Width - this.Controller.View.ClientRectangle.Width < offsetX)
    {
        offsetX = this.Controller.Model.Size.Width - this.Controller.View.ClientRectangle.Width;
    }

    // Prevent y position while offsetY is going outside of the model
    if (this.Controller.Model.Size.Height - this.Controller.View.ClientRectangle.Height < offsetY)
    {
        offsetY = this.Controller.Model.Size.Height - this.Controller.View.ClientRectangle.Height;
    }

    PointF newOrigin = new PointF((float)offsetX, (float)offsetY);

    return newOrigin;
}

 

[VB]

Private Function UpdateOrigin(ByVal xOffset As Integer, ByVal yOffset As Integer) As PointF
Dim magnigication As Double = Me.Controller.Viewer.Magnification / 100R
Dim offsetX As Double = Me.StartPoint.X - xOffset
Dim offsetY As Double = Me.StartPoint.Y - yOffset
 
offsetX = offsetX / magnigication + Me.ViewOrigin.X
offsetY = offsetY / magnigication + Me.ViewOrigin.Y
 
'prevent from negative values
If offsetX < 0 Then
offsetX = 0
End If
If offsetY < 0 Then
offsetY = 0
End If
 
'prevent x position while offsetX is going to outside of model
If Me.Controller.Model.Size.Width - Me.Controller.View.ClientRectangle.Width < offsetX Then
offsetX = Me.Controller.Model.Size.Width - Me.Controller.View.ClientRectangle.Width
End If
 
'prevent y position while offsetY is going to outside of model
If Me.Controller.Model.Size.Height - Me.Controller.View.ClientRectangle.Height < offsetY Then
offsetY = Me.Controller.Model.Size.Height - Me.Controller.View.ClientRectangle.Height
End If
Dim newOrigin As New PointF(CSng(offsetX), CSng(offsetY))
Return newOrigin
End Function
 

 

Here is the sample for restricting the pan operation in grey area instead of model area.

Sample

Conclusion

I hope you enjoyed learning about how to customize the PanTool to restrict the pan operation in the grey area instead of the model area.

You can refer to our  WinForms Diagram feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms Diagram documentation 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 Syncfusio, 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