About the Synchronized MapControl and PageLayoutControl application Sample
[C#]
Maps.cs
using System; using System.Data; using System.Collections; using System.Runtime.InteropServices; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geometry; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.ADF; namespace MapAndPageLayoutSynchApp { /// <summary> /// Implementation of interface IMaps which is eventually a collection of Maps /// </summary> public class Maps : IMaps, IDisposable { //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 /// <summary> /// Dispose the collection /// </summary> public void Dispose() { if (m_array != null) { m_array.Clear(); m_array = null; } } #endregion #region IMaps Members /// <summary> /// Remove the Map at the given index /// </summary> /// <param name="Index"></param> public void RemoveAt(int Index) { if (Index > m_array.Count || Index < 0) throw new Exception("Maps::RemoveAt:\r\nIndex is out of range!"); m_array.RemoveAt(Index); } /// <summary> /// Reset the Maps array /// </summary> public void Reset() { m_array.Clear(); } /// <summary> /// Get the number of Maps in the collection /// </summary> public int Count { get { return m_array.Count; } } /// <summary> /// Return the Map at the given index /// </summary> /// <param name="Index"></param> /// <returns></returns> public IMap get_Item(int Index) { if (Index > m_array.Count || Index < 0) throw new Exception("Maps::get_Item:\r\nIndex is out of range!"); return m_array[Index] as IMap; } /// <summary> /// Remove the instance of the given Map /// </summary> /// <param name="Map"></param> public void Remove(IMap Map) { m_array.Remove(Map); } /// <summary> /// Create a new Map, add it to the collection and return it to the caller /// </summary> /// <returns></returns> public IMap Create() { IMap newMap = new MapClass(); m_array.Add(newMap); return newMap; } /// <summary> /// Add the given Map to the collection /// </summary> /// <param name="Map"></param> public void Add(IMap Map) { if (Map == null) throw new Exception("Maps::Add:\r\nNew Map is mot initialized!"); m_array.Add(Map); } #endregion } }
[Visual Basic .NET]
Maps.vb
Imports Microsoft.VisualBasic Imports System Imports System.Data Imports System.Collections Imports System.Runtime.InteropServices Imports ESRI.ArcGIS.esriSystem Imports ESRI.ArcGIS.Geometry Imports ESRI.ArcGIS.Carto Imports ESRI.ArcGIS.ADF ''' <summary> ''' Implementation of interface IMaps which is eventually a collection of Maps ''' </summary> Public Class Maps : Implements IMaps, IDisposable 'class member - using internally an ArrayList to manage the Maps collection Private m_array As ArrayList = Nothing #Region "class constructor" Public Sub New() m_array = New ArrayList() End Sub #End Region #Region "IDisposable Members" ''' <summary> ''' Dispose the collection ''' </summary> Public Sub Dispose() Implements IDisposable.Dispose If Not m_array Is Nothing Then m_array.Clear() m_array = Nothing End If End Sub #End Region #Region "IMaps Members" ''' <summary> ''' Add the given Map to the collection ''' </summary> ''' <param name="Map"></param> Public Sub Add(ByVal Map As ESRI.ArcGIS.Carto.IMap) Implements ESRI.ArcGIS.Carto.IMaps.Add If Map Is Nothing Then Throw New Exception("Maps::Add:" & Constants.vbCrLf & "New Map is mot initialized!") End If m_array.Add(Map) End Sub ''' <summary> ''' Get the number of Maps in the collection ''' </summary> Public ReadOnly Property Count() As Integer Implements ESRI.ArcGIS.Carto.IMaps.Count Get Return m_array.Count End Get End Property ''' <summary> ''' Create a new Map, add it to the collection and return it to the caller ''' </summary> ''' <returns></returns> Public Function Create() As ESRI.ArcGIS.Carto.IMap Implements ESRI.ArcGIS.Carto.IMaps.Create Dim newMap As IMap = New MapClass() m_array.Add(newMap) Return newMap End Function ''' <summary> ''' Return the Map at the given index ''' </summary> ''' <param name="Index"></param> ''' <returns></returns> Public ReadOnly Property Item(ByVal Index As Integer) As ESRI.ArcGIS.Carto.IMap Implements ESRI.ArcGIS.Carto.IMaps.Item Get If Index > m_array.Count OrElse Index < 0 Then Throw New Exception("Maps::Item:" & Constants.vbCrLf & "Index is out of range!") End If Return TryCast(m_array(Index), IMap) End Get End Property ''' <summary> ''' Remove the instance of the given Map ''' </summary> ''' <param name="Map"></param> Public Sub Remove(ByVal Map As ESRI.ArcGIS.Carto.IMap) Implements ESRI.ArcGIS.Carto.IMaps.Remove m_array.Remove(Map) End Sub ''' <summary> ''' Remove the Map at the given index ''' </summary> ''' <param name="Index"></param> Public Sub RemoveAt(ByVal Index As Integer) Implements ESRI.ArcGIS.Carto.IMaps.RemoveAt If Index > m_array.Count OrElse Index < 0 Then Throw New Exception("Maps::RemoveAt:" & Constants.vbCrLf & "Index is out of range!") End If m_array.RemoveAt(Index) End Sub ''' <summary> ''' Reset the Maps array ''' </summary> Public Sub Reset() Implements ESRI.ArcGIS.Carto.IMaps.Reset m_array.Clear() End Sub #End Region End Class