您的位置:首页 > 其它

解决从模板中删除IMapSurround对象(图例、指北针、比例尺等)时,报内存错误的情况

2011-06-27 21:09 483 查看
//双击修改地图元素
private void axPageLayoutControl1_OnDoubleClick(object sender, IPageLayoutControlEvents_OnDoubleClickEvent e)
{
try
{
if (pPageLayoutControl.CurrentTool !=null && pPageLayoutControl.CurrentTool != CommonPrintClass.pCommand)
{
return;
}
IPoint pPoint = pPageLayoutControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
IGraphicsContainer pGraphicsContainer = pPageLayoutControl.PageLayout as IGraphicsContainer;
IGraphicsContainerSelect pGraphicsContainerSelect = pPageLayoutControl.PageLayout as IGraphicsContainerSelect;

IEnumElement pEnumElement = pGraphicsContainer.LocateElements(pPoint, 1);

pEnumElement.Reset();
IElement pElement = pEnumElement.Next();
while (pElement != null)
{
if (pElement is IMapFrame)
{
pElement = pEnumElement.Next();
continue;
}

IElement pNewElement = ModifyMapElement(pElement);

if (pNewElement != null)
{
if (pElement is IMapSurroundFrame) //解决从模板中删除IMapSurround对象(图例、指北针、比例尺等)时,报内存错误的情况。
{
IMapSurroundFrame pMapSf = pElement as IMapSurroundFrame;
IMapSurround pMapSurround = pMapSf.MapSurround;
if (pMapSurround is IMarkerNorthArrow || pMapSurround is ILegend || pMapSurround is IScaleBar || pMapSurround is IScaleText)
{
IMap pMap = pPageLayoutControl.ActiveView.FocusMap;
pMapSurround.Map = pMap;
pMap.DeleteMapSurround(pMapSurround);
pPageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);

}
if (pElement!=null)
{
pGraphicsContainer.DeleteElement(pElement);
}
}
else
{
pGraphicsContainer.DeleteElement(pElement);
}
pGraphicsContainer.AddElement(pNewElement, 0);
pGraphicsContainerSelect.SelectElement(pNewElement);
pPageLayoutControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
break;
}
else
{
return;
//break;
}
}
}
catch
{
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐