ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapTool Class / OnToolMouseDown Method
A MapViewMouseButtonEventArgs that contains the event data.
Example

In This Topic
    OnToolMouseDown Method (MapTool)
    In This Topic
    Occurs when a mouse button is pressed on the view.
    Syntax
    Protected Overridable Sub OnToolMouseDown( _
       ByVal args As MapViewMouseButtonEventArgs _
    ) 
    protected virtual void OnToolMouseDown( 
       MapViewMouseButtonEventArgs args
    )

    Parameters

    args
    A MapViewMouseButtonEventArgs that contains the event data.
    Remarks
    This method is intended to perform synchronous operations associated with a mouse down event. To perform any asynchronous operations set the handled property on the MapViewMouseButtonEventArgs to true and override the HandleMouseDownAsync virtual method.
    Example
    How to position an embeddable control inside a MapView
    public ProSnippetMapTool()
    {
      //Set the MapTool base class' OverlayControlID to the DAML id of your embeddable control in the constructor
      OverlayControlID = "ProAppModule1_EmbeddableControl1";
    }
    
    // Override the MapTool base class' OverlayControlPositionRatio property to set the position of the embeddable control
    protected static void OnToolMouseDown(MapViewMouseButtonEventArgs e)
    {
      if (e.ChangedButton == MouseButton.Left)
        e.Handled = true;
    }
    
    // Override the MapTool base class' HandleMouseDownAsync method to set the position of the embeddable control
    protected static Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
    {
      return QueuedTask.Run(() =>
      {
        Point
              //assign the screen coordinate clicked point to the MapTool base class' OverlayControlLocation property.
              OverlayControlPositionRatio = e.ClientPoint;
      });
    }
    Translates a point in map coordinates to a point in page coordinates
    {
      //Note: Must be on QueuedTask.Run
      var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.BlackRGB, 8);
      //Convert the clicked point in client coordinates to the corresponding map coordinates.
      //clicked point can be from a Map Tool's HandleMouseDownAsync callback.
      //MapViewMouseButtonEventArgs ClientPoint property.
      Point clickedPoint;
      var clickedMapPoint = MapView.Active.ClientToMap(clickedPoint);
      ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(string.Format("X: {0} Y: {1} Z: {2}",
          mapPoint.X, mapPoint.Y, mapPoint.Z), "Map Coordinates");
      //Get the corresponding layout point
      var pointOnLayoutFrame = mapFrame.MapToPage(mapPoint);
    
      //Create a point graphic on the Layout.
      var cimGraphicElement = new CIMPointGraphic
      {
        Location = pointOnLayoutFrame,
        Symbol = pointSymbol.MakeSymbolReference()
      };
      //Or use GraphicFactory
      var cimGraphicElement2 = GraphicFactory.Instance.CreateSimpleGraphic(
              pointOnLayoutFrame, pointSymbol);
    
      ElementFactory.Instance.CreateGraphicElement(layout, cimGraphicElement);
      ElementFactory.Instance.CreateGraphicElement(layout, cimGraphicElement2);
    }
    Create a tool to the return coordinates of the point clicked in the map
    internal class GetMapCoordinates : MapTool
    {
      protected override void OnToolMouseDown(MapViewMouseButtonEventArgs e)
      {
        if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
          e.Handled = true; //Handle the event args to get the call to the corresponding async method
      }
    
      protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
      {
        return QueuedTask.Run(() =>
        {
          //Convert the clicked point in client coordinates to the corresponding map coordinates.
          var mapPoint = MapView.Active.ClientToMap(e.ClientPoint);
          ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(string.Format("X: {0} Y: {1} Z: {2}",
                      mapPoint.X, mapPoint.Y, mapPoint.Z), "Map Coordinates");
        });
      }
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also