设置图例 边框 背景 AE C#

代码是在PageLayout里面设置的Border,Shadow,还有MapGrid,但愿对你有帮助,可以尝试参考
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Carto ;
using ESRI.ArcGIS .PageLayoutControl ;
using ESRI.ArcGIS .SystemUI;
using ESRI.ArcGIS .Framework ;
using ESRI.ArcGIS .CartoUI;
namespace DrawPage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            
        }
       

        private void BorderMenuItem_Click(object sender, EventArgs e)
        {
            ChangeBorder();
        }
        private void BackgroundMenuItem_Click(object sender, EventArgs e)
        {
            ChangeBackGround();
        }
        private void ShadowMenuItem_Click(object sender, EventArgs e)
        {
            ChangeShadow();
        }
        private void MapGridMenuItem_Click(object sender, EventArgs e)
        {
            MapGrid();
        }

        //改变MapFrame的边框(border):
        private void ChangeBorder()
        {
            IActiveView pActiveView;
            IGraphicsContainer pGraphicsContainer;
            IMap pMap;
            IMapFrame pMapFrame;
            pActiveView = axPageLayoutControl1.PageLayout as IActiveView;
            pMap = pActiveView.FocusMap;
            pGraphicsContainer = pActiveView as IGraphicsContainer;
            pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IStyleSelector pStyleSelector;
            //新建一个边框选择器对象
            pStyleSelector = new BorderSelectorClass();
            bool m_bOK;

            m_bOK = pStyleSelector.DoModal(axPageLayoutControl1.hWnd);
            if (!m_bOK) return;
            IBorder pBorder;
            //得到一个IBorder对象
            pBorder = pStyleSelector.GetStyle(0) as IBorder;
            pMapFrame.Border = pBorder;
            axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewBackground, null, null);
        }
        //改变背景
        private void ChangeBackGround()
        {
            IActiveView pActiveView;
            IGraphicsContainer pGraphicsContainer;
            IMapFrame pMapFrame;
            IMap pMap;

            pActiveView = axPageLayoutControl1.PageLayout as IActiveView;
            pMap = pActiveView.FocusMap;
            pGraphicsContainer = pActiveView as IGraphicsContainer;
            pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IStyleSelector pStyleSelector;
            pStyleSelector = new BackgroundSelectorClass();
            //显示选择对象框对象给用户
            bool m_bOK;
            m_bOK = pStyleSelector.DoModal(axPageLayoutControl1.hWnd);
            //当用户按下(cancel时退出程序)
            if (!m_bOK) return;
            IBackground pBackground;
            //获得一个背景对象
            pBackground = pStyleSelector.GetStyle(0) as IBackground;
            //设置背景属性
            pMapFrame.Background = pBackground;
            axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewBackground, null, null);
        }
        //改变阴影Shadow属性
        private void ChangeShadow()
        {
            IActiveView pActiveView;
            IGraphicsContainer pGraphicsContainer;
            IMapFrame pMapFrame;
            IMap pMap;
            pActiveView = axPageLayoutControl1.PageLayout as IActiveView;
            pMap = pActiveView.FocusMap;
            pGraphicsContainer = pActiveView as IGraphicsContainer;
            pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;
            IStyleSelector pStyleSelector;
            pStyleSelector = new ShadowSelectorClass();
            //显示选择对象框对象给用户
            bool m_bOK;
            m_bOK = pStyleSelector.DoModal(axPageLayoutControl1.hWnd);
            //如果用户按cancel按钮则退出 
            if (!m_bOK) return;
            IShadow pShadow;
            //从选择器中得到一个IShadow对象
            pShadow = pStyleSelector.GetStyle(0) as IShadow;
            IFrameProperties pFrameProperties;
            pFrameProperties = pMapFrame as IFrameProperties;
            //设置框架的阴影属性
            pFrameProperties.Shadow = pShadow;
            axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewBackground, null, null);
        }
        //选择选择对话框的方式
        private void MapGrid()
        {
            IActiveView pActiveView;
            IGraphicsContainer pGraphicsContainer;
            IMapFrame pMapFrame;
            IMap pMap;

            pActiveView = axPageLayoutControl1.PageLayout as IActiveView;
            pMap = pActiveView.FocusMap;
            pGraphicsContainer = pActiveView as IGraphicsContainer;
            pMapFrame = pGraphicsContainer.FindFrame(pMap) as IMapFrame;

            IStyleSelector pStyleSelector;
            pStyleSelector = new MapGridSelectorClass();
            bool m_bOK;
            m_bOK = pStyleSelector.DoModal(axPageLayoutControl1.hWnd);
            if (!m_bOK) return;

            IMapGrid pMapGrid;
            pMapGrid = pStyleSelector.GetStyle(0) as IMapGrid;
            IMapGrids pMapGrids;
            pMapGrids = pMapFrame as IMapGrids;
            //先清除已经存在的MapGrid对象
            pMapGrids.ClearMapGrids();
            if (pMapGrid != null)
            {
                //将选择的MapGrid对象添加进MapGrids中
                pMapGrids.AddMapGrid(pMapGrid);
            }
            axPageLayoutControl1.Refresh(esriViewDrawPhase.esriViewBackground, null, null);
        }

posted @ 2012-05-26 09:03  LinHugh  阅读(1289)  评论(1编辑  收藏  举报