[GIS] How to draw one rectangle in ArcObjects

arcobjectscmap-drawingopenlayers-2optimization

Is there button in ArcObjects "draw rectangle" such as in openlayers?

Update

Well, I use this code for drawing:

ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = Map1.ActiveView.ScreenDisplay;
screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)
    ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache);
ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColor();
rgbColor.Red = 255;

ESRI.ArcGIS.Display.IColor color = rgbColor;
ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new
    ESRI.ArcGIS.Display.SimpleFillSymbol();
simpleFillSymbol.Color = color;

ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as
    ESRI.ArcGIS.Display.ISymbol;
ESRI.ArcGIS.Display.IRubberBand rubberBand = new
    ESRI.ArcGIS.Display.RubberEnvelope();
ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay,
    symbol);
screenDisplay.SetSymbol(symbol);
screenDisplay.DrawRectangle(geometry as ESRI.ArcGIS.Geometry.IEnvelope);
screenDisplay.FinishDrawing();
...
ArcGisToolbar.CurrentTool.Deactivate();
ArcGisToolbar.CurrentTool = null;
ICommand command = this.ArcGisToolbar.CommandPool.get_Command(3); // button "pan"
Map1.CurrentTool = (ITool)command;

But there is a problem. When I activate this instrument (button "select") again, I already start selecting the area (from the point, where I begin drawing the polygon)

Best Answer

First of all I would use:

ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberPolygonClass();

instead of using the RubberEnvelope method

then later do:

screenDisplay.DrawPolygon(geometry);

instead of screenDisplay.DrawRectangle(...)

see if that gets you further.

When getting Feedback for the rectangle via mouse Events I'd do the following: In OnMouseDown use:

INewEnvelopeFeedback envFb = new NewEnvelopeFeedback();
            envFb.Display = activeView.ScreenDisplay;
            envFb.Start(pt);

assign the envFb to a IDisplayfeedback df

In OnMouseMove do:

df.MoveTo(pt)

In OnMouseUp do:

IEnvelope env = ((INewEnvelopeFeedback)df).Stop();

pt is always the position of your mouse cursor.