解决从模板中删除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
{
}
}
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
{
}
}
相关文章推荐
- 解决fastjson内存对象重复/循环引用json错误
- 解决fastjson内存对象重复/循环引用json错误
- GDI对象错误:CBRUSH释放、CreateSolidBrush的内存释放与内存泄露问题及其解决方法
- 微信app支付返回-1错误的情况解决方法
- 关于vc6.0中常见的因为工程设置project setting设置不对而造成连接错误的一些情况和解决方法(转)
- 【QC开发相关】解决无法创建TDConnection(OTAClient.dll中提供)对象的问题(错误0x800703e6)
- 解决xShell4某些情况下按删除键会输出^H的问题
- 挂载swap,解决内存不足的编译错误
- 调试遇到ASSERT错误或容器溢出的情况的解决办法
- Server 对象 错误 'ASP 0177 : 800401f3'解决方法
- Delphi 2010 启动报“displayNotification: 内存不够”错误临时解决办法
- VS2015卸载疑难解决 和 (VS2010)cvtres.exe不能删除及连接错误解决
- SQL错误:无法删除对象 '****',因为该对象正由一个 FOREIGN KEY 约束引用。
- 错误类型 Server 对象, ASP 0177 (0x800401F3)无效的类别字符串—解决方法
- c++函数在传入对象参数和返回对象时候的内存调用情况
- 关于JPA中对于一对多双向关联下对象迭代产生占内存溢出问题的解决
- 2008-07-11 11:54 K3 10.3版 登录时出现 "定义的应用程序或对象错误" 错误代码:1726(6BEH) 的解决方法
- excel2010_此工作薄包含嵌入对象_可能不发从这些对象中删除个人信息_的解决方法
- 使用SqlBulkCopy对象进行大容量复制数据出现Datardader已经存在的错误的解决方法
- AO+Java实现比例尺、指北针、图名、图例的添加(ArcGIS Add-in for Java)