C# – How to Draw a Rectangle on a Map Using ArcObjects

arcmaparcobjectsc

I have two points, Ipoint upperRight; and Ipoint lowerLeft; points.

from the previous points i can get the height and the width for the rectangle.

How can i draw a rectangle on the map?.

I think i should use IGraphicsContainer.AddElement Method, but i don't know how, i searched through the internet but didn't find any useful example.

Best Answer

This is the code to draw a rectangle to page layout view.

IEnvelope env = element.Geometry.Envelope;

if (env != null) {
IPageLayout pLayout = activeView as IPageLayout;
IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;
graphicsContainer.Reset();
IRectangleElement rectangleElement = new RectangleElementClass();
IElement elem = rectangleElement as IElement;
elem.Geometry = env;
graphicsContainer .AddElement(elem, 0);
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
Related Question