This document is archived and information here might be outdated.  Recommended version.


Draw Point Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Draw Point Snippet

Draws a point on the screen where in the ActiveView where the mouse is clicked. The X and Y coordinates come from a mouse down click when the user is interacting with the application.

[C#]
///<summary>Draws a point on the screen where in the ActiveView where the mouse is clicked. The X and Y coordinates come from a mouse down click when the user is interacting with the application.</summary>
///
///<param name="activeView">An IActiveView interface</param>
///<param name="x">An System.Int32 that is device (screen) coordinates from the application. Example: 300</param>
///<param name="y">An System.Int32 that is device (screen) coordinates from the application. Example: 400</param>
/// 
///<remarks>Ideally, this function would be called from within the OnMouseDown event that was created with the ArcGIS base tool template. The X and Y values would come from the OnMouseDown e.X and e.Y values.</remarks>
public void DrawPoint(ESRI.ArcGIS.Carto.IActiveView activeView, System.Int32 x, System.Int32 y)
{

  if (activeView == null)
  {
    return;
  }
  ESRI.ArcGIS.Display.IScreenDisplay screenDisplay=activeView.ScreenDisplay;


  // Constant
  screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache); // Explicit Cast
  ESRI.ArcGIS.Display.ISimpleMarkerSymbol simpleMarkerSymbol=new ESRI.ArcGIS.Display.SimpleMarkerSymbolClass();

  ESRI.ArcGIS.Display.ISymbol symbol=simpleMarkerSymbol as ESRI.ArcGIS.Display.ISymbol; // Dynamic Cast
  screenDisplay.SetSymbol(symbol);
  ESRI.ArcGIS.Display.IDisplayTransformation displayTransformation=screenDisplay.DisplayTransformation;

  // x and y are in device coordinates
  ESRI.ArcGIS.Geometry.IPoint point=displayTransformation.ToMapPoint(x, y);


  screenDisplay.DrawPoint(point);
  screenDisplay.FinishDrawing();
}
[Visual Basic .NET]
'''<summary>Draws a point on the screen where in the ActiveView where the mouse is clicked. The X and Y coordinates come from a mouse down click when the user is interacting with the application.</summary>
'''
'''<param name="activeView">An IActiveView interface</param>
'''<param name="x">An System.Int32 that is device (screen) coordinates from the application. Example: 300</param>
'''<param name="y">An System.Int32 that is device (screen) coordinates from the application. Example: 400</param>
''' 
'''<remarks>Ideally, this function would be called from within the OnMouseDown event that was created with the ArcGIS base tool template. The X and Y values would come from the OnMouseDown e.X and e.Y values.</remarks>
Public Sub DrawPoint(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal x As System.Int32, ByVal y As System.Int32)

  If activeView Is Nothing Then
    Return
  End If

  Dim screenDisplay As ESRI.ArcGIS.Display.IScreenDisplay=activeView.ScreenDisplay

  ' Constant
  screenDisplay.StartDrawing(screenDisplay.hDC, CShort(ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache))
  Dim simpleMarkerSymbol As ESRI.ArcGIS.Display.ISimpleMarkerSymbol=New ESRI.ArcGIS.Display.SimpleMarkerSymbolClass

  Dim symbol As ESRI.ArcGIS.Display.ISymbol=TryCast(simpleMarkerSymbol, ESRI.ArcGIS.Display.ISymbol) ' Dynamic Cast
  screenDisplay.SetSymbol(symbol)
  Dim displayTransformation As ESRI.ArcGIS.Display.IDisplayTransformation=screenDisplay.DisplayTransformation

  ' X and Y are in device coordinates
  Dim point As ESRI.ArcGIS.Geometry.IPoint=displayTransformation.ToMapPoint(x, y)

  screenDisplay.DrawPoint(point)
  screenDisplay.FinishDrawing()

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Display
  • ESRI.ArcGIS.Geometry