创建新元素并设置风格的一般步骤如下:
1、创建一个新的图形元素(LineElement, MarkerElement,PolygonElement,TextElement等)
2、给新元素创建合适的新符号(LineSymbol,TextSymbol,FillSymbol等)
3、创建新的颜色对象(RGBcolor,CMYColor,HLSColor,HSYColor)
4、定义颜色值
5、把颜色赋给符号
6、定义符号的风格
7、把符号赋给图形元素
IElement pElement;
ITextElement pTextElement = new TextElementClass();
pElement = pTextElement as IElement;
IColor pTextColor = new RgbColor();
pTextColor.RGB = Color.FromA#000000.ToArgb();
stdole.IFontDisp pFont = new stdole.StdFontClass() as stdole.IFontDisp;
pFont.Size = 20;
ITextSymbol pTextSymbol = new TextSymbol();
pTextSymbol.Color = pTextColor;
pTextSymbol.Font = pFont;
pTextSymbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;//水平方向居中
pTextSymbol.VerticalAlignment = esriTextVerticalAlignment.esriTVATop;//垂直方向上对齐
pTextElement.Text = "图形元素";
pTextElement.Symbol = pTextSymbol;
IPoint pPt = new PointClass();
pPt.X = (pMapframeElementEnvelope.XMin + pMapframeElementEnvelope.XMax) / 2;
pPt.Y = pMapframeElementEnvelope.YMin;
pElement.Geometry = pPt;
pElemprops = (IElementProperties)pElement;
pElemprops.Name = "textelement";//设置元素名称
ITransform2D pTransform2D = pTextElement as ITransform2D;
pTransform2D.Rotate(pPt, System.Math.PI / 2);//旋转90度
IGraphicsContainer pGraphicsCont = (IGraphicsContainer)AxPageLayoutControl1.PageLayout;//AxMapControl.Map
pGraphicsCont.AddElement((IElement)pTextElement, 0);