ArcObjects操作PageLayoutControl中元素位置,以圖框、ITextSymbol爲例

//設置單位爲釐米
axPageLayoutControl3.PageLayout.Page.Units = esriUnits.esriCentimeters;

IGraphicsContainer graphicsContainer = axPageLayoutControl3.PageLayout as IGraphicsContainer;

//獲取圖框
IMapFrame mf = graphicsContainer.FindFrame(axPageLayoutControl3.ActiveView.FocusMap) as IMapFrame;
            
//設置圖框範圍
IEnvelope en1 = new EnvelopeClass();
en1.PutCoords(0,0,10,10);
IElement ele = mf as IElement;
ele.Geometry = en1;

ITextElement pTextElement = new TextElementClass();
pTextElement.Text = "國家測繪地理信息局";

ITextSymbol pTextSymbol = new TextSymbolClass();
IRgbColor redColor = new RgbColorClass();
redColor.Red = 0;
redColor.Green = 0;
redColor.Blue = 0;
redColor.UseWindowsDithering = true;
pTextSymbol.Color = redColor as IColor;
pTextSymbol.Size = 32;
pTextElement.Symbol = pTextSymbol;

//字號到釐米換算  一個字的寬度=size/72.0*2.54
//說明:
//字號 1約等於1/72英寸, 1英寸=2.54釐米
IPoint pt = new PointClass();
pt.X = 3;
pt.Y = 10;
pt.X = pt.X +  pTextElement.Text.Length * (32 / 72.0 * 2.54)/2;
pt.Y = pt.Y;// - 32 / 72.0 * 2.54/2;
            
IElement element = (IElement)pTextElement;
element.Geometry = pt;axPageLayoutControl3.ActiveView.GraphicsContainer.AddElement((IElement)pTextElement, 0);

axPageLayoutControl3.ActiveView.Refresh();
axPageLayoutControl3.Refresh();

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章