)
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

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

Platform: WinForms |
Control: Diagram |
Published Date: January 19, 2016 |
Last Revised Date: May 31, 2019

To restricting the pan operation in Grey area instead of Model area.

In Diagram control, we can restrict the pan operation in Grey area instead of Model area. It 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 magnigication = this.Controller.Viewer.Magnification / 100d;
double offsetX = this.StartPoint.X - xOffset;
double offsetY = this.StartPoint.Y - yOffset;
 
offsetX = offsetX / magnigication + this.ViewOrigin.X;
offsetY =  offsetY / magnigication + this.ViewOrigin.Y;
 
//prevent from negative values
if (offsetX < 0)
offsetX = 0;
if (offsetY < 0)
offsetY = 0;
 
//prevent x position while offsetX is going to outside of 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 to outside of 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

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