ImageGear PDF v25.2 - Updated
ZoomToRectangle Method (ImGearPresentationPageDisplay)
Example 




ImageGear.Presentation Assembly > ImageGear.Display Namespace > ImGearPresentationPageDisplay Class : ZoomToRectangle Method
ImGearZoomInfo object with new zoom attributes.
Specified device rectangle.
Performs zooming to specified device rectangle and returns new zoom information.
Syntax
'Declaration
 
Public Sub ZoomToRectangle( _
   ByVal pageView As IImGearScrollableView, _
   ByVal rect As ImGearRectangle _
) 
'Usage
 
Dim instance As ImGearPresentationPageDisplay
Dim pageView As IImGearScrollableView
Dim rect As ImGearRectangle
 
instance.ZoomToRectangle(pageView, rect)
public void ZoomToRectangle( 
   IImGearScrollableView pageView,
   ImGearRectangle rect
)
public: void ZoomToRectangle( 
   IImGearScrollableView* pageView,
   ImGearRectangle rect
) 
public:
void ZoomToRectangle( 
   IImGearScrollableView^ pageView,
   ImGearRectangle rect
) 

Parameters

pageView
ImGearZoomInfo object with new zoom attributes.
rect
Specified device rectangle.
Remarks
This method calculates the zoom and scroll values, so that the specified rectangle is fitted to ClipRect and zoom image is fitted to the rectangle calculated. For both horizontal and vertical zoom attributes, it sets ImGearZoomComponentInfo.Fixed field to true, calculates and modifies ImGearZoomComponentInfo.Value field, the horizontal and vertical scroll positions, and returns new instance of ImGearZoomInfo object with new zoom attributes.
Example
// Variable to toggle if user is currently selecting an area.
private bool m_bZoomToRectSelect = false;
// Set of points defining the selected area.
private ImGearPoint[] igPointsZoomToRect;
// Color of selection box.
private Color m_SelectorColor = Color.White;

// Method to return appropriate height for a specific width 
// based upon the size of a scrollable view.
private int GetHeight(IImGearScrollableView igScrollableView, int Width)
{
    return Width * igScrollableView.ClientRectangle.Height / igScrollableView.ClientRectangle.Width;
}

private void menuZoomToRect_Click(object sender, EventArgs e)
{
    // Menu item used to toggle if Zoom to Rectangle is on or not.
    menuZoomToRect.Checked = !menuZoomToRect.Checked;
}

private void imGearPageView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (menuZoomToRect.Checked)
    {
        // Enter Zoom to Rectangle selection mode.
        m_bZoomToRectSelect = true;
        // Create a new pair of points to define the rectangle, 
        // setting the first point to the current position.
        igPointsZoomToRect = new ImGearPoint[2];
        igPointsZoomToRect[0].X = e.X;
        igPointsZoomToRect[0].Y = e.Y;
        // Register method to draw the selection rectangle.
        imGearPageView.RegisterAfterDraw(
            new ImGearPageView.AfterDraw(DrawSelector));
    }
}

private void imGearPageView1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (m_bZoomToRectSelect)
    {
        // Leave Zoom to Rectangle selection mode.
        imGearPageView.RegisterAfterDraw(null);
        m_bZoomToRectSelect = false;
        // Record the second point of the zoom rectangle,
        // normalizing it to the view's aspect ratio.
        igPointsZoomToRect[1].X = e.X;
        igPointsZoomToRect[1].Y = igPointsZoomToRect[0].Y +
            GetHeight(imGearPageView, Math.Abs(igPointsZoomToRect[1].X - igPointsZoomToRect[0].X) + 1) - 1;
        // Create a rectangle based upon the 2 points.
        ImGearRectangle igRectangle = new ImGearRectangle(igPointsZoomToRect[0], igPointsZoomToRect[1]);
        // Cancel the zoom if it would be for a 0x0 or 1x1 rectangle.
        if (igRectangle.Width <= 1 || igRectangle.Height <= 1)
            return;
        // Zoom to the selected rectangle
        imGearPageView.Display.ZoomToRectangle(imGearPageView, igRectangle);
        imGearPageView.Invalidate();
        // Disable Zoom to Rectangle.
        menuZoomToRect.Checked = false;
    }
}

private void imGearPageView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
    if (m_bZoomToRectSelect)
    {
        // Record the second point of the zoom rectangle,
        // normalizing it to the view's aspect ratio.
        igPointsZoomToRect[1].X = e.X;
        igPointsZoomToRect[1].Y = igPointsZoomToRect[0].Y +
            GetHeight(imGearPageView, Math.Abs(igPointsZoomToRect[1].X - igPointsZoomToRect[0].X) + 1) - 1;
        // Cause a redraw which will update the zoom selection rectangle.
        imGearPageView.Invalidate();
    }
}

private void DrawSelector(System.Drawing.Graphics gr)
{
    if (m_bZoomToRectSelect)
    {
        // Create a new pen to draw dotted lines.
        Pen pen = new Pen(m_SelectorColor);
        pen.DashStyle = DashStyle.Dot;
        // Define the currently selected zoom rectangle.
        ImGearRectangle igRectangleZoom = new ImGearRectangle(igPointsZoomToRect[0], igPointsZoomToRect[1]);
        // Draw the selection box.
        gr.DrawRectangle(pen, igRectangleZoom.Left, igRectangleZoom.Top,
            igRectangleZoom.Width, igRectangleZoom.Height);
    }
}
'Variable to toggle if user is currently selecting an area.
Private m_bZoomToRectSelect As Boolean = False
'Set of points defining the selected area.
Private igPointsZoomToRect() As ImGearPoint
'Color of selection box.
Private m_SelectorColor As Color = Color.White

'Function to return appropriate height for a specific width 
' based upon the size of a scrollable view.
Private Function GetHeight(ByVal igScrollableView As IImGearScrollableView, ByVal Width As Integer) As Integer
    GetHeight = Width * igScrollableView.ClientRectangle.Height / igScrollableView.ClientRectangle.Width
End Function


Private Sub menuZoomtoRect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                Handles menuZoomtoRect.Click
    menuZoomtoRect.Checked = Not menuZoomtoRect.Checked
End Sub

Private Sub ImGearPageView1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
                Handles ImGearPageView1.MouseDown
    If (menuZoomtoRect.Checked) Then
        'Enter Zoom to Rectangle selection mode.
        m_bZoomToRectSelect = True
        'Create a new pair of points to define the rectangle, 
        ' setting the first point to the current position.
        ReDim igPointsZoomToRect(2)
        igPointsZoomToRect(0).X = e.X
        igPointsZoomToRect(0).Y = e.Y
        'Register function to draw the selection rectangle.
        ImGearPageView1.RegisterAfterDraw( _
            New ImGearPageView.AfterDraw(AddressOf DrawSelector))
    End If
End Sub

Private Sub ImGearPageView1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
                Handles ImGearPageView1.MouseUp
    If (m_bZoomToRectSelect) Then
        'Leave Zoom to Rectangle selection mode.
        ImGearPageView1.RegisterAfterDraw(Nothing)
        m_bZoomToRectSelect = False
        'Record the second point of the zoom rectangle,
        ' normalizing it to the view's aspect ratio.
        igPointsZoomToRect(1).X = e.X
        igPointsZoomToRect(1).Y = igPointsZoomToRect(0).Y + _
            GetHeight(ImGearPageView1, Math.Abs(igPointsZoomToRect(1).X - igPointsZoomToRect(0).X) + 1) - 1
        'Create a rectangle based upon the 2 points.
        Dim igRectangle As ImGearRectangle = New ImGearRectangle(igPointsZoomToRect(0), igPointsZoomToRect(1))
        'Cancel the zoom if it would be for a 0x0 or 1x1 rectangle.
        If (igRectangle.Width <= 1 Or igRectangle.Height <= 1) Then
            Return
        End If
        'Zoom to the selected rectangle
        ImGearPageView1.Display.ZoomToRectangle(ImGearPageView1, igRectangle)
        ImGearPageView1.Invalidate()
        'Disable Zoom to Rectangle.
        menuZoomtoRect.Checked = False
    End If
End Sub

Private Sub ImGearPageView1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
                Handles ImGearPageView1.MouseMove
    If (m_bZoomToRectSelect) Then
        'Record the second point of the zoom rectangle,
        ' normalizing it to the view's aspect ratio.
        igPointsZoomToRect(1).X = e.X
        igPointsZoomToRect(1).Y = igPointsZoomToRect(0).Y + _
            GetHeight(ImGearPageView1, Math.Abs(igPointsZoomToRect(1).X - igPointsZoomToRect(0).X) + 1) - 1
        'Cause a redraw which will update the zoom selection rectangle.
        ImGearPageView1.Invalidate()
    End If
End Sub

Private Sub DrawSelector(ByVal gr As System.Drawing.Graphics)
    If (m_bZoomToRectSelect) Then
        'Create a new pen to draw dotted lines.
        Dim pen As Pen = New Pen(m_SelectorColor)
        Pen.DashStyle = DashStyle.Dot
        'Define the currently selected zoom rectangle.
        Dim igRectangleZoom As ImGearRectangle = New ImGearRectangle(igPointsZoomToRect(0), igPointsZoomToRect(1))
        'Draw the selection box.
        gr.DrawRectangle(pen, igRectangleZoom.Left, igRectangleZoom.Top, igRectangleZoom.Width, igRectangleZoom.Height)
    End If
End Sub
See Also

Reference

ImGearPresentationPageDisplay Class
ImGearPresentationPageDisplay Members
IImGearScrollableView Interface
ImGearRectangle Structure

Is this page helpful?
Yes No
Thanks for your feedback.