IGraphicsContain 删除元素

刚想实现删除axMapControl 中指定的元素。实现该功能首先得获取欲删除的Element。

下面代码为遍历方式获取其中的Element

   
IGraphicsContainer pGrappic=axMapControl1.Actiview as IGrapicsContainer
 IElement pElement = pGraphic.Next();

IGraphicsContainer 还提供了交互式的获取Elments,其中包括以point的选的 pGraphic.LocateElements和以Envelope 选的pGraphic.LocateElementsByEnvelope。

此为第一种方式。即需人际交互式。

第二种方式为: 在创建Element的时候指定Element的名字,删除的时候删除指定的名称的Element的

 IElement pElement = pGraphic.Next();

            while (pElement != null)
            {
                IElementProperties pd = pElement as IElementProperties;
                if (pd.Name == name)
                {
                    pGraphic.DeleteElement(pElement);
                   
                }
                pElement = pGraphic.Next();
            }

给Element 指定名字的时候也是得QI到IElementProperties 接口

IElementProperties pEl=pElement as IElementProperties.
pEl.Name="****";
原文地址:https://www.cnblogs.com/myyouthlife/p/2592150.html