Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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);
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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