Adding SimpleFillSymbol to ArcMap document

667
1
09-23-2011 12:30 PM
BKuiper
Occasional Contributor III
Hi,

I'm trying to add a SimpleFillSymbol to an ArcMap document on a specific location on the document/map.

I tried a couple of thing, but failed and i'm pretty sure this should be a relatively easy task.

I was trying to use the GraphicsContainer to add an element which contains the Symbol but couldn't get it working.

Can anybody give me some pointers on how to achieve this?

This is what i'm trying to do:

IMxDocument document = ArcMap.Application.Document as IMxDocument;
IMap map = document.FocusMap;
IGraphicsContainer graphicsContainer = document.PageLayout as IGraphicsContainer;

ISimpleFillSymbol symbol = myObject.Symbol;

...code which adds the symbol to the element...
...code to set the geometry (x,y and width and height)...

graphicsContainer.AddElement(element, 0); 


Thank you very much!
0 Kudos
1 Reply
JeffreyHamblin
New Contributor III
You are probably missing setting the ISimpleFillSymbol to the IFillShapeElement.Symbol.

private void PerformTest4()
{
    IActiveView activeView = ArcMap.Document.ActiveView;

    if (activeView is IPageLayout)
    {

        IRgbColor rgbColor = new RgbColorClass();

        // Fill, red
        ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
        rgbColor.Red = 255;
        rgbColor.Green = 0;
        rgbColor.Blue = 0;
        simpleFillSymbol.Color = rgbColor;

        // Outline, black, set outline to fill
        ISimpleLineSymbol outline = new SimpleLineSymbolClass();
        rgbColor.Red = 0;
        rgbColor.Green = 0;
        rgbColor.Blue = 0;
        outline.Color = rgbColor;
        outline.Width = 1.5;
        outline.Style = esriSimpleLineStyle.esriSLSSolid;
        simpleFillSymbol.Outline = outline;

        // Set the element's symbol
        IFillShapeElement fillShapeElement = new RectangleElementClass();
        fillShapeElement.Symbol = simpleFillSymbol;
        IElement element = fillShapeElement as IElement;

        // Set the size of the element to 5 x 2 in display units (ie. inches),
        // located in lower-left corner of page
        IEnvelope envelope = new EnvelopeClass();
        envelope.PutCoords(0, 0, 5, 2);
        element.Geometry = envelope;

        // Add the text box to the layout
        IGraphicsContainer graphicsContainer = ArcMap.Document.PageLayout as IGraphicsContainer;
        graphicsContainer.AddElement(element, 0);

        activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);


    }

}
0 Kudos