




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、第一講:桌面GIS應(yīng)用程序框架的建立本講主要是使用MapControl、PageLayoutControl、ToolbarControl、TOCControl四個(gè)控件建立起基本的桌面GIS應(yīng)用程序框架。最終成果預(yù)覽如下:1、新建項(xiàng)目啟動(dòng)VS2005,選擇“文件|新建|項(xiàng)目”,在項(xiàng)目類型中選擇Visual C#,再選擇Windows應(yīng)用程序模板,輸入名稱“3sdnMap”,點(diǎn)擊確定。在解決方案管理器中將“”重命名為“”,在設(shè)計(jì)視圖中,選中窗體,將其屬性中的“Text”改為“3sdnMap”。2、添加控件選擇工具箱中的“菜單和工具欄|MenuStrip”,將其拖入窗體。選擇工具箱中的“ArcGIS
2、 Windows Forms”節(jié),將“ToolbarControl”控件拖入窗體,并將其屬性中的Dock設(shè)置為Top。選擇工具箱中的“菜單和工具欄|StatusStrip”,將其拖入到窗體。選擇工具箱中的“容器|SplitContainer”容器拖入窗體,并將其屬性中的Dock設(shè)置為Fill。將TabControl控件拖入Panel1,將Alignment屬性設(shè)置為Bottom,Dock屬性設(shè)置為Fill。點(diǎn)擊TabPages屬性右邊的按鈕,彈出TabPage集合編輯器,將tabPage1的Name設(shè)置為tabPageLayer,Text設(shè)置為圖層,將tabPage2的Name設(shè)置為tabPa
3、geProperty,Text設(shè)置為屬性。如下所示。 選擇“圖層”選項(xiàng)卡,拖入TOCControl控件,設(shè)置Dock屬性為Fill。選擇“屬性”選項(xiàng)卡,拖入DataGridView控件,設(shè)置Dock屬性為Fill。拖入TabControl控件到Panel2,設(shè)置Dock屬性為Fill。并上述類似的方法,將兩個(gè)選項(xiàng)卡的Name和Text分別設(shè)置為:(tabPageMap、地圖),(tabPageLayout,制版)。選擇“地圖”選項(xiàng)卡,拖入MapControl控件,設(shè)置Dock屬性為Fill。選擇“制版”選項(xiàng)卡,拖入PageLayoutControl控件,設(shè)置Dock屬性為Fill。最后將Lic
4、enseControl控件拖入到窗體的任意地方。按F5編譯運(yùn)行,可以看到剛才布局好的程序界面了。3、控件綁定通過(guò)以上步驟添加的控件還只是單獨(dú)存在,而我們的程序需要各控件間協(xié)同工作,因此要進(jìn)行控件綁定。分別右擊ToolbarControl、TOCControl控件,將Buddy設(shè)置為axMapControl1,如下圖所示。 這樣,工具條和圖層控件就與地圖控件關(guān)聯(lián)了。4、添加工具此時(shí),工具條中還沒(méi)有任何工具,添加的方法也很簡(jiǎn)單。右擊ToolbarControl,選擇“屬性|Items”,點(diǎn)擊Add,選擇Commands選項(xiàng)卡中的Generic,雙擊Open、SaveAs、Redo、Undo即可將相
5、應(yīng)工具添加到工具條。 常見(jiàn)的工具有:Map Navigation中的導(dǎo)航工具,Map Inquiry中的查詢工具,F(xiàn)eature Selection中的選擇工具,你可以根據(jù)需要酌情添加工具。5、編譯運(yùn)行按F5即可編譯運(yùn)行程序,至此桌面GIS應(yīng)用程序框架基本框架已經(jīng)搭建好了,你可以通過(guò)工具條的工具打開(kāi)地圖文檔,瀏覽地圖了,效果如開(kāi)篇所示.第二講 菜單的添加及其實(shí)現(xiàn)在上一講中,我們實(shí)現(xiàn)了應(yīng)用程序基本框架,其中有個(gè)小錯(cuò)誤,在此先跟大家說(shuō)明下。在“屬性”選項(xiàng)卡中,我們當(dāng)時(shí)添加的是 DataGridView 控件,這個(gè)控件是用來(lái)顯示數(shù)據(jù)表的,而專門用于屬性的查詢和設(shè)置的控件是 PropertyGrid
6、控件。因此請(qǐng)你刪除“屬性”選項(xiàng)卡中的 DataGridView 控件,再把位于“工具箱 | 所有 Windows 窗體 |PropertyGrid ”(如果沒(méi)有,右擊選擇“選擇項(xiàng)”以添加此控件)控件拖到該選項(xiàng)卡。 在這一講中,主要講解菜單的添加和實(shí)現(xiàn)。 1、 添加菜單 在設(shè)計(jì)視圖中,單擊菜單欄,會(huì)出現(xiàn)“請(qǐng)?jiān)诖颂庢I入”的提示,單擊提示就可以鍵入菜單名稱,如“文件”,再單擊“文件”,即可輸入其下拉子菜單,如下所示: Tips : 每創(chuàng)建一個(gè)菜單,請(qǐng)?jiān)谄鋵傩悦姘逯性O(shè)置 Name 屬性,而且不要為中文,因此 Name 值將是此菜單響應(yīng)函數(shù)的函數(shù)名的一部分,帶中文的函數(shù)名,總是不好吧。 本講中,我們將添
7、加新建( New )、打開(kāi)( Open )、添加數(shù)據(jù)( AddData )、保存( Save )、另存為( SaveAs )、退出( Exit )這些菜單,()內(nèi)為相應(yīng)的 Name 屬性值。 Tips: 你可以在屬性面板中的 Text 屬性中,把菜單名設(shè)置為中英文形式,如“打開(kāi) O pen ”,帶下劃線的 O 表示此項(xiàng)菜單的快捷鍵是字母 O ,設(shè)置方法是在相應(yīng)字母前加上“ & ”字符,如“打開(kāi) &Open ”。但這種快捷鍵只在打開(kāi)此下拉菜單時(shí)才有效,即當(dāng)你單擊“文件”菜單彈出下拉菜單時(shí),按下字母 O 就可以定位到“打開(kāi)”菜單。 還有一種在程序運(yùn)行時(shí)都有效的全局快捷鍵,可以在屬性面板中的“ Sh
8、ortCutKeys ”中設(shè)置。 你還可以在屬性面板中的 Image 屬性中設(shè)置你喜歡的菜單圖標(biāo)。單擊 Image 那一行右邊的按鈕,彈出如下菜單。選擇“項(xiàng)目資源文件”,再單擊導(dǎo)入就可以選擇你的圖標(biāo)了。 最終效果如下所示。 注意,在解決方案面板中,選中剛才添加的所有圖標(biāo),在其屬性面板中將生成操作設(shè)置為“嵌入的資源”,這一點(diǎn)很重要! 2、 實(shí)現(xiàn)相關(guān)菜單 首先定義指針(寫在 public partial class Form1 : Form 下面即可): private ESRI.ArcGIS.Controls.IMapControl3 m_mapControl = null; private E
9、SRI.ArcGIS.Controls.IPageLayoutControl2 m_pageLayoutControl = null; private IMapDocument pMapDocument; 若以上指針無(wú)效,請(qǐng)?zhí)砑右韵乱茫?using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.SystemUI; 在設(shè)計(jì)視圖中的屬性面板中,選
10、擇 Form1 ,即主窗體,單擊事件按鈕(閃電形狀的那個(gè)按鈕),打到“ Load ”事件并雙擊,添加此事件。 在 Form1_Load 函數(shù)中初始化這些指針: / 取得 MapControl 和 PageLayoutControl 的引用 m_mapControl = (IMapControl3)this.axMapControl1.Object; m_pageLayoutControl = (IPageLayoutControl2)this.axPageLayoutControl1.Object; 依次雙擊每個(gè)菜單項(xiàng),添加菜單響應(yīng)函數(shù)。實(shí)現(xiàn)代碼如下: / / 新建地圖命令 / / / pri
11、vate void New_Click(object sender, EventArgs e) / 本命令涉及到 MapControl 和 PageLayoutControl 同步問(wèn)題,將在下一講中實(shí)現(xiàn) / / 打開(kāi)地圖文檔 Mxd 命令 / / / private void Open_Click(object sender, EventArgs e) / 本命令涉及到 MapControl 和 PageLayoutControl 同步問(wèn)題,將在下一講中實(shí)現(xiàn) / / 添加數(shù)據(jù)命令 / / / private void AddData_Click(object sender, EventArgs
12、 e) int currentLayerCount = this.axMapControl1.LayerCount; ICommand pCommand = new ControlsAddDataCommandClass(); pCommand.OnCreate(this.axMapControl1.Object); pCommand.OnClick(); / / 保存地圖文檔命令 / / / private void Save_Click(object sender, EventArgs e) / 首先確認(rèn)當(dāng)前地圖文檔是否有效 If(null!=m_pag&m_mapControl.Chec
13、kMxFile(m_pageLayoutControl.DocumentFilename) / 創(chuàng)建一個(gè)新的地圖文檔實(shí)例 IMapDocument mapDoc = new MapDocumentClass(); / 打開(kāi)當(dāng)前地圖文檔 mapDoc.Open(m_pageLayoutControl.DocumentFilename, string.Empty); / 用 PageLayout 中的文檔替換當(dāng)前文檔中的 PageLayout 部分 mapDoc.ReplaceContents(IMxdContents)m_pageLayoutControl.PageLayout); / 保存地圖
14、文檔 mapDoc.Save(mapDoc.UsesRelativePaths, false); mapDoc.Close(); / / 另存為地圖文檔命令 / / / private void SaveAs_Click(object sender, EventArgs e) / 調(diào)用另存為命令 ICommand command = new ControlsSaveAsDocCommandClass(); command.OnCreate(m_controlsSynchronizer.ActiveControl); command.OnClick(); / / 退出程序 / / / priva
15、te void Exit_Click(object sender, EventArgs e) Application.Exit(); 3、 編譯運(yùn)行 按 F5 編譯運(yùn)行程序。也許你會(huì)發(fā)現(xiàn),菜單命令的實(shí)現(xiàn)方式都是類型的。沒(méi)錯(cuò),在 AE9.2 中,內(nèi)置了許多常用的 Command和 Tool ,如 ControlsAddDataCommandClass 、 ControlsMapZoomInToolClass 、 ControlsMapPanToolClass 等等,這些內(nèi)置對(duì)象在 ESRI.ArcGIS.Controls 命名空間中,你可以對(duì)象瀏覽器中查看。而且這些內(nèi)置對(duì)象的調(diào)用方式都類似,如下
16、所示: / 定義 ICommand command = new ControlsSaveAsDocCommandClass(); / 創(chuàng)建 command.OnCreate(m_controlsSynchronizer.ActiveControl); / 調(diào)用 command.OnClick(); 第三講 MapControl與PageLayoutControl同步在ArcMap中,能夠很方面地進(jìn)行MapView和Layout View兩種視圖的切換,而且二者之間的數(shù)據(jù)是同步顯示的。關(guān)于兩種視圖同步的實(shí)現(xiàn)方法有多種,可以使用ObjectCopy對(duì)象進(jìn)行數(shù)據(jù)硬拷貝,而比較簡(jiǎn)單的方法莫過(guò)于二者共享
17、一份地圖了,這也是最常用的方法。1、新建同步類ControlsSynchronizer在解決方案面板中右擊項(xiàng)目名,選擇“添加|類”,在類別中選擇“Visual C#項(xiàng)目項(xiàng)”,在模板中選擇“類”,輸入類名“”,將以下代碼覆蓋自動(dòng)生成的代碼:using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.IO;using System.Runtime.InteropServices; using ESRI.Ar
18、cGIS.esriSystem;using ESRI.ArcGIS.Carto;using ESRI.ArcGIS.Controls;using ESRI.ArcGIS.SystemUI;namespace _sdnMap / / This class is used to synchronize a gven PageLayoutControl and a MapControl. / When initialized, the user must pass the reference of these control to the class, bind / the control toge
19、ther by calling BindControls which in turn sets a joined Map referenced / by both control; and set all the buddy controls joined between these two controls. / When alternating between the MapControl and PageLayoutControl, you should activate the visible control / and deactivate the other by calling
20、ActivateXXX. / This calss is limited to a situation where the controls are not simultaneously visible. / public class ControlsSynchronizer #region class members private IMapControl3 m_mapControl = null; private IPageLayoutControl2 m_pageLayoutControl = null; private ITool m_mapActiveTool = null; pri
21、vate ITool m_pageLayoutActiveTool = null; private bool m_IsMapCtrlactive = true; private ArrayList m_frameworkControls = null; #endregion #region constructor / / 默認(rèn)構(gòu)造函數(shù) / public ControlsSynchronizer() /初始化ArrayList m_frameworkControls = new ArrayList(); / / 構(gòu)造函數(shù) / / / public ControlsSynchronizer(IMa
22、pControl3 mapControl, IPageLayoutControl2 pageLayoutControl) : this() /為類成員賦值 m_mapControl = mapControl; m_pageLayoutControl = pageLayoutControl; #endregion #region properties / / 取得或設(shè)置MapControl / public IMapControl3 MapControl get return m_mapControl; set m_mapControl = value; / / 取得或設(shè)置PageLayoutC
23、ontrol / public IPageLayoutControl2 PageLayoutControl get return m_pageLayoutControl; set m_pageLayoutControl = value; / / 取得當(dāng)前ActiveView的類型 / public string ActiveViewType get if (m_IsMapCtrlactive) return MapControl; else return PageLayoutControl; / / 取得當(dāng)前活動(dòng)的Control / public object ActiveControl ge
24、t if (m_mapControl = null | m_pageLayoutControl = null) throw new Exception(ControlsSynchronizer:ActiveControl:rnEither MapControl or PageLayoutControl are not initialized!); if (m_IsMapCtrlactive) return m_mapControl.Object; else return m_pageLayoutControl.Object; #endregion #region Methods / / 激活M
25、apControl并解除the PagleLayoutControl / public void ActivateMap() try if (m_pageLayoutControl = null | m_mapControl = null) throw new Exception(ControlsSynchronizer:ActivateMap:rnEither MapControl or PageLayoutControl are not initialized!); /緩存當(dāng)前PageLayout的CurrentTool if (m_pageLayoutControl.CurrentToo
26、l != null) m_pageLayoutActiveTool = m_pageLayoutControl.CurrentTool; /解除PagleLayout m_pageLayoutControl.ActiveView.Deactivate(); /激活MapControl m_mapControl.ActiveView.Activate(m_mapControl.hWnd); /將之前MapControl最后使用的tool,作為活動(dòng)的tool,賦給MapControl的CurrentTool if (m_mapActiveTool != null) m_mapControl.Cur
27、rentTool = m_mapActiveTool; m_IsMapCtrlactive = true; /為每一個(gè)的framework controls,設(shè)置Buddy control為MapControl this.SetBuddies(m_mapControl.Object); catch (Exception ex) throw new Exception(string.Format(ControlsSynchronizer:ActivateMap:rn0, ex.Message); / / 激活PagleLayoutControl并減活MapCotrol / public void
28、 ActivatePageLayout() try if (m_pageLayoutControl = null | m_mapControl = null) throw new Exception(ControlsSynchronizer:ActivatePageLayout:rnEither MapControl or PageLayoutControl are not initialized!); /緩存當(dāng)前MapControl的CurrentTool if (m_mapControl.CurrentTool != null) m_mapActiveTool = m_mapControl
29、.CurrentTool; /解除MapControl m_mapControl.ActiveView.Deactivate(); /激活PageLayoutControl m_pageLayoutControl.ActiveView.Activate(m_pageLayoutControl.hWnd); /將之前PageLayoutControl最后使用的tool,作為活動(dòng)的tool,賦給PageLayoutControl的CurrentTool if (m_pageLayoutActiveTool != null) m_pageLayoutControl.CurrentTool = m_p
30、ageLayoutActiveTool; m_IsMapCtrlactive = false; /為每一個(gè)的framework controls,設(shè)置Buddy control為PageLayoutControl this.SetBuddies(m_pageLayoutControl.Object); catch (Exception ex) throw new Exception(string.Format(ControlsSynchronizer:ActivatePageLayout:rn0, ex.Message); / / 給予一個(gè)地圖, 置換PageLayoutControl和Map
31、Control的focus map / / public void ReplaceMap(IMap newMap) if (newMap = null) throw new Exception(ControlsSynchronizer:ReplaceMap:rnNew map for replacement is not initialized!); if (m_pageLayoutControl = null | m_mapControl = null) throw new Exception(ControlsSynchronizer:ReplaceMap:rnEither MapContr
32、ol or PageLayoutControl are not initialized!); /create a new instance of IMaps collection which is needed by the PageLayout /創(chuàng)建一個(gè)PageLayout需要用到的,新的IMaps collection的實(shí)例 IMaps maps = new Maps(); /add the new map to the Maps collection /把新的地圖加到Maps collection里頭去 maps.Add(newMap); bool bIsMapActive = m_I
33、sMapCtrlactive; /call replace map on the PageLayout in order to replace the focus map /we must call ActivatePageLayout, since it is the control we call ReplaceMaps /調(diào)用PageLayout的replace map來(lái)置換focus map /我們必須調(diào)用ActivatePageLayout,因?yàn)樗悄莻€(gè)我們可以調(diào)用ReplaceMaps的Control this.ActivatePageLayout(); m_pageLayoutC
34、ontrol.PageLayout.ReplaceMaps(maps); /assign the new map to the MapControl /把新的地圖賦給MapControl m_mapControl.Map = newMap; /reset the active tools /重設(shè)active tools m_pageLayoutActiveTool = null; m_mapActiveTool = null; /make sure that the last active control is activated /確認(rèn)之前活動(dòng)的control被激活 if (bIsMapAc
35、tive) this.ActivateMap(); m_mapControl.ActiveView.Refresh(); else this.ActivatePageLayout(); m_pageLayoutControl.ActiveView.Refresh(); / / bind the MapControl and PageLayoutControl together by assigning a new joint focus map / 指定共同的Map來(lái)把MapControl和PageLayoutControl綁在一起 / / / / true if the MapControl
36、 supposed to be activated first,如果MapControl被首先激活,則為true public void BindControls(IMapControl3 mapControl, IPageLayoutControl2 pageLayoutControl, bool activateMapFirst) if (mapControl = null | pageLayoutControl = null) throw new Exception(ControlsSynchronizer:BindControls:rnEither MapControl or Page
37、LayoutControl are not initialized!); m_mapControl = MapControl; m_pageLayoutControl = pageLayoutControl; this.BindControls(activateMapFirst); / / bind the MapControl and PageLayoutControl together by assigning a new joint focus map / 指定共同的Map來(lái)把MapControl和PageLayoutControl綁在一起 / / true if the MapCont
38、rol supposed to be activated first,如果MapControl被首先激活,則為true public void BindControls(bool activateMapFirst) if (m_pageLayoutControl = null | m_mapControl = null) throw new Exception(ControlsSynchronizer:BindControls:rnEither MapControl or PageLayoutControl are not initialized!); /create a new instan
39、ce of IMap /創(chuàng)造IMap的一個(gè)實(shí)例 IMap newMap = new MapClass(); newMap.Name = Map; /create a new instance of IMaps collection which is needed by the PageLayout /創(chuàng)造一個(gè)新的IMaps collection的實(shí)例,這是PageLayout所需要的 IMaps maps = new Maps(); /add the new Map instance to the Maps collection /把新的Map實(shí)例賦給Maps collection maps.
40、Add(newMap); /call replace map on the PageLayout in order to replace the focus map /調(diào)用PageLayout的replace map來(lái)置換focus map m_pageLayoutControl.PageLayout.ReplaceMaps(maps); /assign the new map to the MapControl /把新的map賦給MapControl m_mapControl.Map = newMap; /reset the active tools /重設(shè)active tools m_pa
41、geLayoutActiveTool = null; m_mapActiveTool = null; /make sure that the last active control is activated /確定最后活動(dòng)的control被激活 if (activateMapFirst) this.ActivateMap(); else this.ActivatePageLayout(); / /by passing the applications toolbars and TOC to the synchronization class, it saves you the /managem
42、ent of the buddy control each time the active control changes. This method ads the framework /control to an array; once the active control changes, the class iterates through the array and /calles SetBuddyControl on each of the stored framework control. / / public void AddFrameworkControl(object con
43、trol) if (control = null) throw new Exception(ControlsSynchronizer:AddFrameworkControl:rnAdded control is not initialized!); m_frameworkControls.Add(control); / / Remove a framework control from the managed list of controls / / public void RemoveFrameworkControl(object control) if (control = null) t
44、hrow new Exception(ControlsSynchronizer:RemoveFrameworkControl:rnControl to be removed is not initialized!); m_frameworkControls.Remove(control); / / Remove a framework control from the managed list of controls by specifying its index in the list / / public void RemoveFrameworkControlAt(int index) i
45、f (m_frameworkControls.Count index) throw new Exception(ControlsSynchronizer:RemoveFrameworkControlAt:rnIndex is out of range!); m_frameworkControls.RemoveAt(index); / / when the active control changes, the class iterates through the array of the framework controls / and calles SetBuddyControl on ea
46、ch of the controls. / / the active control private void SetBuddies(object buddy) try if (buddy = null) throw new Exception(ControlsSynchronizer:SetBuddies:rnTarget Buddy Control is not initialized!); foreach (object obj in m_frameworkControls) if (obj is IToolbarControl) (IToolbarControl)obj).SetBud
47、dyControl(buddy); else if (obj is ITOCControl) (ITOCControl)obj).SetBuddyControl(buddy); catch (Exception ex) throw new Exception(string.Format(ControlsSynchronizer:SetBuddies:rn0, ex.Message); #endregion 2、新建Maps類在同步類中,要用到Maps類,用于管理地圖對(duì)象。與新建同步類ControlsSynchronizer類似,我們新建一Maps類,其所有代碼如下所示: using Syste
48、m;using System.Collections;using System.Collections.Generic;using System.Text;using System.Runtime.InteropServices;using ESRI.ArcGIS.Carto;namespace _sdnMap Guid(f27d8789-fbbc-4801-be78-0e3cd8fff9d5) ClassInterface(ClassInterfaceType.None) ProgId(_sdnMap.Maps) public class Maps : IMaps, IDisposable
49、/class member - using internally an ArrayList to manage the Maps collection private ArrayList m_array = null; #region class constructor public Maps() m_array = new ArrayList(); #endregion #region IDisposable Members / / Dispose the collection / public void Dispose() if (m_array != null) m_array.Clea
50、r(); m_array = null; #endregion #region IMaps Members / / Remove the Map at the given index / / public void RemoveAt(int Index) if (Index m_array.Count | Index 0) throw new Exception(Maps:RemoveAt:rnIndex is out of range!); m_array.RemoveAt(Index); / / Reset the Maps array / public void Reset() m_ar
51、ray.Clear(); / / Get the number of Maps in the collection / public int Count get return m_array.Count; / / Return the Map at the given index / / / public IMap get_Item(int Index) if (Index m_array.Count | Index 0) throw new Exception(Maps:get_Item:rnIndex is out of range!); return m_arrayIndex as IM
52、ap; / / Remove the instance of the given Map / / public void Remove(IMap Map) m_array.Remove(Map); / / Create a new Map, add it to the collection and return it to the caller / / public IMap Create() IMap newMap = new MapClass(); m_array.Add(newMap); return newMap; / / Add the given Map to the collec
53、tion / / public void Add(IMap Map) if (Map = null) throw new Exception(Maps:Add:rnNew Map is mot initialized!); m_array.Add(Map); #endregion 3、新建打開(kāi)文檔類OpenNewMapDocument由于從工具欄自帶的打開(kāi)按鈕打開(kāi)地圖文檔的時(shí)候,不會(huì)自動(dòng)進(jìn)行兩種視圖之間的同步,所以我們要自己派生一個(gè)OpenNewMapDocument類,用于打開(kāi)地圖文檔。 右擊項(xiàng)目名,選擇“添加|類”,再選擇ArcGIS類別中的BaseCommand模板,輸入類名為“”。首先
54、添加引用:using System.Windows.Forms;using ESRI.ArcGIS.Carto; 再添加如下成員變量: private ControlsSynchronizer m_controlsSynchronizer = null; 修改默認(rèn)的構(gòu)造函數(shù)如下所示: /添加參數(shù)public OpenNewMapDocument(ControlsSynchronizer controlsSynchronizer) / / TODO: Define values for the public properties /設(shè)定相關(guān)屬性值 base.m_category = Generi
55、c; /localizable text base.m_caption = Open; /localizable text base.m_message = This should work in ArcMap/MapControl/PageLayoutControl; /localizable text base.m_toolTip = Open; /localizable text base.m_name = Generic_Open; /unique id, non-localizable (e.g. MyCategory_MyCommand) /初始化m_controlsSynchro
56、nizer m_controlsSynchronizer = controlsSynchronizer; try / / TODO: change bitmap name if necessary / string bitmapResourceName = GetType().Name + .bmp; base.m_bitmap = new Bitmap(GetType(), bitmapResourceName); catch (Exception ex) System.Diagnostics.Trace.WriteLine(ex.Message, Invalid Bitmap); 再在On
57、Click函數(shù)中添加如下代碼: public override void OnClick() / TODO: Add OpenNewMapDocument.OnClick implementation OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = Map Documents (*.mxd)|*.mxd; dlg.Multiselect = false; dlg.Title = Open Map Document; if (dlg.ShowDialog() = DialogResult.OK) string docName = d
58、lg.FileName; IMapDocument mapDoc = new MapDocumentClass(); if (mapDoc.get_IsPresent(docName) & !mapDoc.get_IsPasswordProtected(docName) mapDoc.Open(docName, string.Empty); IMap map = mapDoc.get_Map(0); m_controlsSynchronizer.ReplaceMap(map); mapDoc.Close(); 在添加類時(shí),模板會(huì)自動(dòng)添加一個(gè)名為“”的圖標(biāo),你可以自己修改或者替換為打開(kāi)的文件夾的
59、圖標(biāo)。4、兩種視圖的同步在中添加成員變量,即同步類對(duì)象: private ControlsSynchronizer m_controlsSynchronizer = null; 在Form1_Load函數(shù)中進(jìn)行初始化工作: /初始化controls synchronization calssm_controlsSynchronizer = new ControlsSynchronizer(m_mapControl, m_pageLayoutControl); /把MapControl和PageLayoutControl綁定起來(lái)(兩個(gè)都指向同一個(gè)Map),然后設(shè)置MapControl為活動(dòng)的Co
60、ntrol m_controlsSynchronizer.BindControls(true); /為了在切換MapControl和PageLayoutControl視圖同步,要添加Framework Control m_controlsSynchronizer.AddFrameworkControl(axToolbarControl1.Object); m_controlsSynchronizer.AddFrameworkControl(this.axTOCControl1.Object);/ 添加打開(kāi)命令按鈕到工具條OpenNewMapDocument openMapDoc = new O
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度物流運(yùn)輸借款協(xié)議方合同
- 二零二五年度航空航天用高溫合金委托生產(chǎn)協(xié)議
- 二零二五年度智能共享單車無(wú)償使用合同范本
- 2025年度門診部護(hù)士長(zhǎng)聘任與管理服務(wù)合同
- 職業(yè)插畫師插畫設(shè)計(jì)服務(wù)合同
- 房地產(chǎn)經(jīng)紀(jì)人獨(dú)家代理合同書
- 產(chǎn)品創(chuàng)意與策劃流程手冊(cè)
- 歷史文物保護(hù)與遺址發(fā)掘試題及答案
- 人工智能輔助的智能環(huán)境保護(hù)監(jiān)測(cè)系統(tǒng)開(kāi)發(fā)協(xié)議
- 大健康產(chǎn)業(yè)數(shù)字化健康服務(wù)平臺(tái)建設(shè)
- 消防水箱安裝施工方案
- GB/T 24804-2023提高在用電梯安全性的規(guī)范
- 人教版PEP五年級(jí)英語(yǔ)上冊(cè)全冊(cè)課件
- 【重慶長(zhǎng)安汽車公司績(jī)效管理現(xiàn)狀、問(wèn)題及優(yōu)化對(duì)策(7600字論文)】
- 家鄉(xiāng)-延安課件
- Codesys中文編程手冊(cè)
- 教育系統(tǒng)后備干部筆試試題及參考答案
- 無(wú)人機(jī)導(dǎo)航與通信技術(shù)PPT完整全套教學(xué)課件
- 六年級(jí)奧數(shù)(學(xué)生版)
- 鋼結(jié)構(gòu)設(shè)計(jì)原理全套PPT完整教學(xué)課件
- 《植物學(xué)教學(xué)資料》第2章細(xì)胞與組織2馬煒梁版
評(píng)論
0/150
提交評(píng)論