Hi everyone. This is an issue I have been trying to tackle for a while and decided to reach out for help. I am creating an ESRI ArcGIS Desktop Add-In that allows the user to draw a polygon and then have it added to the map. I am able to capture the polygon and add it to the map, the issue is the transparency. Currently and by default it is 100% opacity and solid. I want to make it around 50% opacity so the user can see the data behind it.
Here is the code I have so far:
public static void AddPolygonToMap(IActiveView ActiveViewInstance, IGeometry NewGeo) { //Local Variable Declaration var fillShapeElement = default(IFillShapeElement); var element = default(IElement); var graphicsContainer = default(IGraphicsContainer); var simpleFilleSymbol = default(ISimpleFillSymbol); var newRgbColor = default(IRgbColor); var lineSymbol = default(ILineSymbol); //Use the IElement interface to set the Envelope Element's geo element = new PolygonElement(); element.Geometry = NewGeo; //QI for the IFillShapeElement interface so that the symbol property can be set fillShapeElement = element as IFillShapeElement; //Create a new fill symbol simpleFilleSymbol = new SimpleFillSymbol(); //Create a new color marker symbol of the color black; newRgbColor = new RgbColor(); newRgbColor.Red = 0; newRgbColor.Green = 0; newRgbColor.Blue = 0; //Create a new line symbol so that we can set the width outline lineSymbol = new SimpleLineSymbol(); lineSymbol.Color = newRgbColor; lineSymbol.Width = 2; //Setup the Simple Fill Symbol simpleFilleSymbol.Color = newRgbColor; simpleFilleSymbol.Style = esriSimpleFillStyle.esriSFSHollow; simpleFilleSymbol.Outline = lineSymbol; fillShapeElement.Symbol = simpleFilleSymbol; //QI for the graphics container from the active view allows access to basic graphics layer graphicsContainer = ActiveViewInstance as IGraphicsContainer; //Add the new element at Z order 0 graphicsContainer.AddElement((IElement)fillShapeElement, 0); //Show the new graphic ActiveViewInstance.Refresh(); }
I know that this is possible somehow and I am sure it's just a line or two missing but any help would be much appreciated.
V/r,
Josh
Solved! Go to Solution.
If all the GraphicElement visible on the map are supposed to be transparent, then probably you could use the IDisplayFilter (TransparencyDisplayFilter) to set the transparency other than 0 or 255.
Could you provide a proposed implementation?
Something like this
// as an example, we'll draw a rectangle in the middle of the current extent
var rectangle = activeView.Extent;
rectangle.Expand(0.5, 0.5, true); // create a rectangle in the middle
var lineSymbol = new SimpleLineSymbolClass();
lineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
lineSymbol.Color = new RgbColorClass {Red = 0, Green = 0, Blue = 0};
var fillSymbol = new SimpleFillSymbolClass
{
Style = esriSimpleFillStyle.esriSFSSolid,
Outline = lineSymbol,
Color = new RgbColorClass { Red = 255, Green = 0, Blue = 0}
};
var screenDisplay = activeView.ScreenDisplay;
var transparencyDisplayFilter = new TransparencyDisplayFilterClass
{
Transparency = 127
};
try
{
screenDisplay.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache);
screenDisplay.Filter = transparencyDisplayFilter;
screenDisplay.SetSymbol(fillSymbol);
screenDisplay.DrawRectangle(rectangle);
}
finally
{
screenDisplay.FinishDrawing();
}
thejus thanks for the reply. I have actually seen this before. This does work great for the drawing no doubt but when you go to actually add the element to screen permanently it is no longer applicable. Does that make sense?