HOW TO

Capture a mouse click in map units

Last Published: April 25, 2020

Summary

Instructions provided capture a mouse click in map units. A mouse click can be captured using the MouseDown event of a UI Tool Control. This event returns the mouse click coordinates in device units. Use the IDisplayTransformation::ToMapPoint method to convert from device units to map units.

Procedure



  1. Start ArcMap.
  2. Open the Visual Basic Editor.

    In ArcMap, select Tools > Macros > Visual Basic Editor.

  3. Create a new UIToolControl.

    A. Select Tools > Customize to open the Customize dialog box.
    B. Click the Commands tab.
    C. Select UIControls from the Categories list box.
    D. Select Untitled from the Save In dropdown list to save the tool to this map document. Select Normal to save the tool to all ArcMap documents on your machine.
    E. Click New UIControl.
    F. Select UIToolControl and Create.
    G. Drag the new UIToolControl to the toolbar of your choice.
    H. Close the Customize dialog box.



    Note:
    For more information on creating a UIControl, see the ArcGIS Desktop Help topic 'How to create custom commands with VBA.'

  4. Right-click the UIToolControl and select View Source.
  5. Copy this code into the UIToolControl's mousedown event.

    Code:
    ' x and y define the point the user clicked in device units

    Dim pPoint As IPoint
    Dim pApp As IMxApplication
    Set pApp = Application

    ' convert mouse click to map units
    Set pPoint = pApp.Display.DisplayTransformation.ToMapPoint(x, y)

    MsgBox "User clicked coordinate: " & pPoint.x & ", " & pPoint.y

Article ID:000007163

Software:
  • ArcMap 8 x
  • ArcMap 9 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic