How to draw a point on the screen


Drawing a point on the screen

The following code draws a point on the screen in the ActiveView where the mouse is clicked. The x,y coordinates come from a mousedown click event when the user interacts with the application. In this example, the point is not persisted on the screen but is removed after the next screen refresh.
[VB.NET]
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
[C#]
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();
}


See Also:

How to draw a polyline on the screen
How to draw a polygon on the screen
How to draw a rectangle on the screen




Development licensing Deployment licensing
ArcView ArcView
ArcEditor ArcEditor
ArcInfo ArcInfo
Engine Developer Kit Engine Runtime