Category / Section
Customizing the PanTool to restricting Pan operation in Grey area instead of Model area
2 mins read
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.