How to draw a polyline on the screen

Summary This article shows how to draw a polyline using IRubberBand. In this example, the polyline will not persist on the screen but will be removed after the next screen refresh.

Drawing a polyline on the screen

The following code draws a polyline 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.
static void drawPolyline(IActiveView activeView)throws Exception{
    IScreenDisplay screenDisplay = activeView.getScreenDisplay();

    screenDisplay.startDrawing(screenDisplay.getHDC(), (short)
    IRgbColor rgbColor = new RgbColor();

    IColor color = rgbColor;
    ISimpleLineSymbol simpleLineSymbol = new SimpleLineSymbol();

    ISymbol symbol = (ISymbol)simpleLineSymbol;
    IRubberBand rubberBand = new RubberLine();
    IGeometry geometry = rubberBand.trackNew(screenDisplay, symbol);

See Also:

How to draw a point 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