功能1:增加pageLayoutControl控件(layoutMain),用于显示地图layoutMain的位置与mapGIS完全重合在菜单栏中添加两个菜单dataViewMenu和layoutViewMenu,前者作用是显示mapGIS,后者的作用是显示layoutMain。窗体加载过程中(load)添加如下代码//在初始化过程中,mapGIS为可见的,即layoutMain为隐藏的,二者只能有一个可见。mapGIS.Visible=true;layoutMain.Visible=false;dataViewMenu.Checked=true;layoutViewMenu.Checked=false;//通过mapGIS的位置给layoutMain定位,注意:此过程一定要在给mapGIS确定位置后进行layoutMain.Left=mapGIS.Left;layoutMain.Top=mapGIS.Top;layoutMain.Width=mapGIS.Width;layoutMain.Height=mapGIS.Height;//允许通过拖拽打开地图数据m_pEffect=esriControlsDragDropEffect.esriDragDropNone;在窗体重绘过程中加一下代码://通过mapGIS的位置给layoutMain定位,注意:此过程一定要在给mapGIS确定位置后进行layoutMain.Left=mapGIS.Left;layoutMain.Top=mapGIS.Top;layoutMain.Width=mapGIS.Width;layoutMain.Height=mapGIS.Height;给dataViewMenu添加单击事件在此事件中,改变mapGIS和layoutMain的visible,并在菜单上选中相应的菜单。并设置与toolGIS关联的控件。privatevoiddataViewMenu_Click(objectsender,EventArgse){mapGIS.Visible=true;toolGIS.SetBuddyControl(mapGIS);layoutMain.Visible=false;dataViewMenu.Checked=true;layoutViewMenu.Checked=false;}layoutViewMenu的单击事件:privatevoidlayoutViewMenu_Click(objectsender,EventArgse){mapGIS.Visible=false;layoutMain.Visible=true;toolGIS.SetBuddyControl(layoutMain);dataViewMenu.Checked=false;layoutViewMenu.Checked=true;CopyMapFromMaptoPageLayout();}添加方法CopyMapFromMaptoPageLayout(),作用是将mapGIS中的地图拷贝至layoutMain中。publicvoidCopyMapFromMaptoPageLayout(){ESRI.ArcGIS.esriSystem.IObjectCopypObjectCopy;pObjectCopy=newESRI.ArcGIS.esriSystem.ObjectCopy();objectpToCopyMap;pToCopyMap=mapGIS.ActiveView.FocusMap;objectpCopiedMap;pCopiedMap=pObjectCopy.Copy(pToCopyMap);objectpToOverwriteMap;pToOverwriteMap=layoutMain.ActiveView.FocusMap;pObjectCopy.Overwrite(pCopiedMap,pToOverwriteMap);if(pToOverwriteMap==null)return;IMapFramem_pMapFrame;m_pMapFrame=(IMapFrame)layoutMain.GraphicsContainer.FindFrame(layoutMain.ActiveView.FocusMap);m_pMapFrame.ExtentType=esriExtentTypeEnum.esriExtentScale;layoutMain.Page.IsPrintableAreaVisible=true;layoutMain.ActiveView.Extent=mapGIS.ActiveView.Extent;layoutMain.Refresh();layoutMain.ZoomToWholePage();}为mapGIS添加ViewRefreshed事件privatevoidmapGIS_OnViewRefreshed(objectsender,IMapControlEvents2_OnViewRefreshedEvente){CopyMapFromMaptoPageLayout();}为了完善功能,将右键菜单的功能实现中添加如下代码OverMapUpData();CopyMapFromMaptoPageLayout();此过程是为了在LayoutView状态下,右键添加数据或者删除数据时,layout显示依旧正确。功能2:通过鼠标拖拽读取数据为mapGIS添加OneDrop事件privatevoidmapGIS_OnOleDrop(objectsender,IMapControlEvents2_OnOleDropEvente){IDataObjectHelperpDadaObject;pDadaObject=(IDataObjectHelper)e.dataObjectHelper;esriControlsDropActionaction;action=e.dropAction;e.effect=(int)esriControlsDragDropEffect.esriDragDropNone;if(action==esriControlsDropAction.esriDropEnter)if(pDadaObject.CanGetFiles()||pDadaObject.CanGetNames())m_pEffect=esriControlsDragDropEffect.esriDragDropCopy;if(action==esriControlsDropAction.esriDropOver)e.effect=(int)m_pEffect;string[]pFillePaths;IFileNamepFileName;IEnumNamepEnumName;INamepName;if(action==esriControlsDropAction.esriDropped){if(pDadaObject.CanGetFiles()){pFillePaths=(string[])pDadaObject.GetFiles();for(shorti=0;ipFillePaths.Length;i++){if(mapGIS.CheckMxFile(pFillePaths[i]))mapGIS.LoadMxFile(pFillePaths[i]);else{pFileName=newFileNameClass();pFileName.Path=pFillePaths[i];CreateLayer((IName)pFileName);}}}elseif(pDadaObject.CanGetNames()){pEnumName=pDadaObject.GetNames();pEnumName.Reset();pName=pEnumName.Next();do{CreateLayer(pName);pName=pEnumName.Next();}while(pName!=null);}}}publicvoidCreateLayer(INamepName){try{mapGIS.MousePointer=esriControlsMousePointer.esriPointerHourglass;ILayerFactoryHelperpLayerFactoryHelper;pLayerFactoryHelper=newLayerFactoryHelperClass();IEnumLayerpEnumLayer;pEnumLayer=pLayerFactoryHelper.CreateLayersFromName(pName);pEnumLayer.Reset();ILayerpLayer;pLayer=pEnumLayer.Next();do{mapGIS.AddLayer(pLayer);pLayer=pEnumLayer.Next();}while(pLayer!=null);mapGIS.MousePointer=esriControlsMousePointer.esriPointerDefault;}catch(Exception){}}