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
- Add a new UIToolControl to any toolbar.
- Right-click on the tool and select view source - paste the code below here.
- Make sure the names of the controls match, the sample assumes the tool is called UIToolControl1.
- Completely close VBA so mouse events fire.
- Select the tool and drag a rectangle on the focus map.
- The focus map extent changes to best fit the drawn rectangle.
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