This document is archived and information here might be outdated.  Recommended version.


Zoom by Ratio Snippet (ArcObjects .NET 10.4 SDK)
ArcObjects Library Reference

Zoom by Ratio Snippet

Zoom in ActiveView using a ratio of the current extent.

[C#]
///<summary>Zoom in ActiveView using a ratio of the current extent.</summary>
///  
///<param name="activeView">An IActiveView interface.</param>
///<param name="zoomRatio">A Double that is the ratio to zoom in. Less that 1 zooms in (Example: .75), greater than 1 zooms out (Example: 2).</param>
///   
///<remarks>Both the width and height ratio of the zoomed area is preserved.</remarks>
public void ZoomByRatio(ESRI.ArcGIS.Carto.IActiveView activeView, System.Double zoomRatio)
{
  if(activeView == null || zoomRatio < 0)
  {
    return;
  }
  ESRI.ArcGIS.Geometry.IEnvelope envelope=activeView.Extent;
  envelope.Expand(zoomRatio, zoomRatio, true);
  activeView.Extent=envelope;
  activeView.Refresh();
}
[Visual Basic .NET]
'''<summary>Zoom in ActiveView using a ratio of the current extent.</summary>
'''  
'''<param name="activeView">An IActiveView interface.</param>
'''<param name="zoomRatio">A Double that is the ratio to zoom in. Less that 1 zooms in (Example: .75), greater than 1 zooms out (Example: 2).</param>
'''   
'''<remarks>Both the width and height ratio of the zoomed area is preserved.</remarks>
Public Sub ZoomByRatio(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal zoomRatio As System.Double)

  If activeView Is Nothing OrElse zoomRatio < 0 Then
    Return
  End If

  Dim envelope As ESRI.ArcGIS.Geometry.IEnvelope=activeView.Extent
  envelope.Expand(zoomRatio, zoomRatio, True)
  activeView.Extent=envelope
  activeView.Refresh()

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Geometry
  • ESRI.ArcGIS.System