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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Customizing the OverviewControl to restricting to change the viewport as negative location

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

Restrict to move the viewport as outside of the model

In Diagram’s overview control, we can restrict the movement of viewport outside the model. It can be achieved by customizing the Diagram’s “OverviewControl” class. From the customized class, override the draw method and draw the “ViewPort” logically based on the model area.

Here is the code example for restricting to move the viewport as outside of the model.

[C#]

protected override void DrawViewport(Graphics grfx)
{
if (Diagram.View != null)
{
if ((ViewportBounds.X + ViewportBounds.Width > rcDisplayArea.X + rcDisplayArea.Width || ViewportBounds.X < rcDisplayArea.X)
|| (ViewportBounds.Y + ViewportBounds.Height > rcDisplayArea.Y + rcDisplayArea.Height || ViewportBounds.Y < rcDisplayArea.Y))
{
float heightDiff = 0;
float widthDiff = 0;
PointF pt = PointF.Empty;
                    
if (ViewportBounds.X + ViewportBounds.Width > rcDisplayArea.X + rcDisplayArea.Width)
{
//to Prevent move the viewport in right
widthDiff = (ViewportBounds.X + ViewportBounds.Width) - (rcDisplayArea.X + rcDisplayArea.Width);
pt.X = ViewportBounds.X - widthDiff;
}
else
{
//To prevent move the viewport in top
if (ViewportBounds.X < rcDisplayArea.X)
{
widthDiff = rcDisplayArea.X - ViewportBounds.X;
}
pt.X = ViewportBounds.X + widthDiff;
}
 
                    
if (ViewportBounds.Y + ViewportBounds.Height > rcDisplayArea.Y + rcDisplayArea.Height)
{
//to prevent move the viewport in bottom
heightDiff = (ViewportBounds.Y + ViewportBounds.Height) - (rcDisplayArea.Y + rcDisplayArea.Height);
pt.Y = ViewportBounds.Y - heightDiff;
} 
else
{
//To prevent move the viewport in left
if (ViewportBounds.Y < rcDisplayArea.Y)
{
heightDiff = rcDisplayArea.Y - ViewportBounds.Y;
}
pt.Y = ViewportBounds.Y + heightDiff;
}
 
SizeF size = ViewportBounds.Size;
if (size.Width > rcDisplayArea.Width)
size.Width = rcDisplayArea.Width;
if (size.Height > rcDisplayArea.Height)
size.Height = rcDisplayArea.Height;
 
ViewportBounds = new RectangleF(pt.X, pt.Y, size.Width, size.Height);
if (!(this.Diagram.Size.Width == 0 || this.Diagram.Size.Height == 0))
{
this.vpRenderer.DrawViewport(grfx, this.ForeColor);
}
}
else
{
base.DrawViewport(grfx);
}
}
}

 

[VB]

Protected Overrides Sub DrawViewport(ByVal grfx As Graphics)
If Diagram.View IsNot Nothing Then
If (ViewportBounds.X + ViewportBounds.Width > rcDisplayArea.X + rcDisplayArea.Width OrElse ViewportBounds.X < rcDisplayArea.X) OrElse (ViewportBounds.Y + ViewportBounds.Height > rcDisplayArea.Y + rcDisplayArea.Height OrElse ViewportBounds.Y < rcDisplayArea.Y) Then
Dim heightDiff As Single = 0
Dim widthDiff As Single = 0
Dim pt As PointF = PointF.Empty
 
If ViewportBounds.X + ViewportBounds.Width > rcDisplayArea.X + rcDisplayArea.Width Then
'to Prevent move the viewport in right
widthDiff = (ViewportBounds.X + ViewportBounds.Width) - (rcDisplayArea.X + rcDisplayArea.Width)
pt.X = ViewportBounds.X - widthDiff
Else
'To prevent move the viewport in top
If ViewportBounds.X < rcDisplayArea.X Then
widthDiff = rcDisplayArea.X - ViewportBounds.X
End If
pt.X = ViewportBounds.X + widthDiff
End If
 
 
If ViewportBounds.Y + ViewportBounds.Height > rcDisplayArea.Y + rcDisplayArea.Height Then
'to prevent move the viewport in bottom
heightDiff = (ViewportBounds.Y + ViewportBounds.Height) - (rcDisplayArea.Y + rcDisplayArea.Height)
pt.Y = ViewportBounds.Y - heightDiff
Else
'To prevent move the viewport in left
If ViewportBounds.Y < rcDisplayArea.Y Then
heightDiff = rcDisplayArea.Y - ViewportBounds.Y
End If
pt.Y = ViewportBounds.Y + heightDiff
End If
 
Dim size As SizeF = ViewportBounds.Size
If size.Width > rcDisplayArea.Width Then
size.Width = rcDisplayArea.Width
End If
If size.Height > rcDisplayArea.Height Then
size.Height = rcDisplayArea.Height
End If
 
ViewportBounds = New RectangleF(pt.X, pt.Y, size.Width, size.Height)
If Not(Me.Diagram.Size.Width = 0 OrElse Me.Diagram.Size.Height = 0) Then
Me.vpRenderer.DrawViewport(grfx, Me.ForeColor)
End If
Else
MyBase.DrawViewport(grfx)
End If
End If
End Sub
 

 

Here is the sample for restricting to move the viewport as outside of the model.

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.

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