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


Well, I use this code for drawing:

ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = Map1.ActiveView.ScreenDisplay;
screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)
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
simpleFillSymbol.Color = color;

ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as
ESRI.ArcGIS.Display.IRubberBand rubberBand = new
ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay,
screenDisplay.DrawRectangle(geometry as ESRI.ArcGIS.Geometry.IEnvelope);
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)

  • what sdk Version do you use? – Chris P Oct 29 '13 at 12:51

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:


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;

assign the envFb to a IDisplayfeedback df

In OnMouseMove do:


In OnMouseUp do:

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

pt is always the position of your mouse cursor.

  • 1
    Thanks. I draw rectangle, not polygon. Nowdays, I use two events: OnMouseDown (the left upper point) OnMouseUp (the right lower point, then draw rectangle) – novicegis Oct 29 '13 at 13:09
  • 1
    Yes that should work using the INewEnvelopeFeedback for instance. So is your issue solved or what is the remaining problem? – Chris P Oct 29 '13 at 13:13
  • I can draw rectangle on the Map. But I write additional code to functions: _OnMouseUp _OnMouseDown. I think it is not good. When I use example with "screenDisplay.DrawRectangle" I have the problem with instrument "select". When i activate this tool again I am already starting draw the rectangle (but I must only select the area). instrument "select". When i activate this tool again I already starting draw the polygone (but I must only select elemnts). – novicegis Oct 29 '13 at 13:32
  • what Instrument "select" are you referring to? Is that a custom tool made by you or some Standard selection tool in ArcMap? I edit my original answer to add some info on how I'd handle the mouse Events. – Chris P Oct 29 '13 at 14:01
  • I wonder whether the problem is that you don't call stop() for the envelopeFeedback (see my edited post above). Additional code in the mouseevent functions is generally seen not a problem. – Chris P Oct 29 '13 at 14:17

There are a lot of useful information and snippets of code in the ArcObjects online help from which you can start. For instance:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.