How to TrackPan


There are two approaches to panning - TrackPan and the PanStart, PanMoveTo, and PanStop group. TrackPan is the easiest to use as it takes care of all the mouse events, performs the pan, and refreshes the display when the pan is complete.
See the How to create an advanced pan tool tip for another pan sample that uses the PanStart approach. This sample also shows how to make a pan tool that works in all views and magnifier windows and works almost identically to ArcMap's pan tool.

How to use

  1. Add a UIToolControl to any toolbar.
  2. Right-click on the tool and select view source.
  3. Paste the code below into VBA. Make sure the names of the UIControls matches.
  4. Close VBA to enable mouse events.
  5. Use the command to pan the focus map.
[VBA]
Option Explicit

Private Sub UIToolControl1_MouseDown(ByVal button As Long, ByVal shift As Long, ByVal x As Long, ByVal y As Long)
    Dim pScreenDisplay As IScreenDisplay
    Dim pActiveView As IActiveView
    Dim pMxDoc As IMxDocument
    
    Set pMxDoc = Application.Document
    Set pActiveView = pMxDoc.FocusMap
    Set pScreenDisplay = pActiveView.ScreenDisplay
    pScreenDisplay.TrackPan
End Sub