Engine中如何将ILegend转为IElement?即实现右键选中Legend弹出的Convert To Gtaphics功能?

Engine中如何将ILegend转为IElement?即实现右键选中Legend弹出的Convert To Gtaphics功能?
已邀请:

朱新颖

赞同来自:

【解决办法】:
1,获取ILegend;
2,将ILegend转为IGraphicsComposite,执行get_Graphics()方法即可。



IPageLayout pageLayout = axPageLayoutControl1.PageLayout;
IActiveView activeView = (IActiveView)pageLayout;
IGraphicsContainer graphicsContainer = pageLayout as IGraphicsContainer;
graphicsContainer.Reset();
IElement element = graphicsContainer.Next();
while (element != null)
{
if (element is IMapSurroundFrame)
{
IMapSurround mapSurround = ((IMapSurroundFrame)element).MapSurround;
if (mapSurround is ILegend)
{
ILegend legend = (ILegend)mapSurround;
IGraphicsComposite graphComp = (IGraphicsComposite)legend;
IEnumElement enumElem = graphComp.get_Graphics(activeView.ScreenDisplay, element.Geometry.Envelope);
enumElem.Reset();
IElement ele = enumElem.Next();
while(ele !=null)
{
graphicsContainer.AddElement(ele,0);//可以将其添加到当前PageLayout里
ele = enumElem.Next();
}

}

}
element = graphicsContainer.Next();
}
}

要回复问题请先登录注册