How to zoom in by a user provided extent


This sample zooms in on the focus map based on the extent drawn by the user. The samples uses a UIToolControl to get the mouse down event; inside this event, the user is asked to drag out a rectangle specifying the extent the map will be zoomed to.

How to use

  1. Add a new UIToolControl to any toolbar.
  2. Right-click on the tool and select view source - paste the code below here.
  3. Make sure the names of the controls match, the sample assumes the tool is called UIToolControl1.
  4. Completely close VBA so mouse events fire.
  5. Select the tool and drag a rectangle on the focus map.
  6. The focus map extent changes to best fit the drawn rectangle.
[VBA]
Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
    'Zoom in on the focus map based on user drawn rectangle
    Dim pMxDoc As IMxDocument
    Dim pActiveView As IActiveView
    Dim pRubberBand As IRubberBand
    
    Set pMxDoc = Application.Document
    Set pActiveView = pMxDoc.FocusMap
    Set pRubberBand = New RubberEnvelope
    pActiveView.Extent = pRubberBand.TrackNew(pActiveView.ScreenDisplay, Nothing)
    pActiveView.Refresh
End Sub