添加图廓线,图廓线的真实面目是FrameElement,添加方法如下:
private void wndBtnAddNeatLine_ItemClick(object sender, ItemClickEventArgs e)
{
//实验代码:
//添加整理图廓线 图廓线的真实面目是FrameElement
FrameElement pFrameElement = new FrameElementClass();
IFrameElement pIFrameElement = pFrameElement as IFrameElement;
pIFrameElement.Border = new SymbolBorder();
//如果要放在页面边缘内部:
IEnvelope pEnvelope = wndPageLayout.Page.PrintableBounds;
pFrameElement.Geometry = pEnvelope;
//这个是Page的边缘,按照这个Envelop,将Border的gap设置为-10即可。
IFrameProperties pFrameProperties = pIFrameElement as IFrameProperties;
IBorder pBorder = pFrameProperties.Border;
if (pBorder != null)
{
IFrameDecoration pFrameDecoration = pBorder as IFrameDecoration;
pFrameDecoration.HorizontalSpacing = -10;
pFrameDecoration.VerticalSpacing = -10;
}
pFrameProperties.Border = pBorder; //注意IFrameDecoration::Border是非引用接口(■―■),因此一定要反代回去,否则值不会改变
pFrameElement.Geometry = pEnvelope;
//添加进去。放在页面内部的话,必须创建单独的FrameElement对象
wndPageLayout.ActiveView.GraphicsContainer.AddElement(pFrameElement as IElement, 0);
wndPageLayout.ActiveView.Refresh();
}
上面这段代码,在Page的内部页面边缘添加整理线,如果要把NeatLine放到所有选择了的要素或者所有要素周围,则应该用下面的做法:
private void wndBtnAddNeatLine_ItemClick(object sender, ItemClickEventArgs e)
{
//实验代码:
//添加整理图廓线 图廓线的真实面目是FrameElement
FrameElement pFrameElement = new FrameElementClass();
IFrameElement pIFrameElement = pFrameElement as IFrameElement;
pIFrameElement.Border = new SymbolBorder();
//否则,放到所有选择了的要素或者所有要素周围
IGraphicsContainer graphicsContainer = wndPageLayout.PageLayout as IGraphicsContainer;
IGraphicsContainerSelect pGraphicsContainerSelect = wndPageLayout.PageLayout as IGraphicsContainerSelect;
IEnumElement pEnumElement = pGraphicsContainerSelect.SelectedElements;
IGroupElement pGroupElement = new GroupElementClass();
pEnumElement.Reset();
IElement pElement = pEnumElement.Next();
while (pElement != null)
{
pGroupElement.AddElement(pElement);
pElement = pEnumElement.Next();
}
if (pGroupElement.ElementCount != 0)
{
//获取包含所有选择要素的最小矩形框
IEnvelope pEnvelope = new EnvelopeClass();
IElement pTagGroupElement = pGroupElement as IElement;
pTagGroupElement.QueryBounds(wndPageLayout.ActiveView.ScreenDisplay as IDisplay, pEnvelope);
//这种方式获取的矩形框和实用QueryBounds得到的结果一样
IPolygon pPolygon = new PolygonClass();
pTagGroupElement.QueryOutline(wndPageLayout.ActiveView.ScreenDisplay as IDisplay, pPolygon);
pElement = pFrameElement as IElement;
//
//如果要组合所有要素,就将GroupElement和新建的FrameElement组合成新的GroupElement,然后加进去
IGroupElement pGroupElement2 = new GroupElementClass();
pGroupElement2.AddElement(pTagGroupElement);
pGroupElement2.AddElement(pElement);
pElement = pGroupElement2 as IElement;
//
//如果不组合,就直接添加新建的GroupElement
wndPageLayout.ActiveView.GraphicsContainer.AddElement(pElement as IElement, 0);
wndPageLayout.ActiveView.Refresh();
}
}