ArcObjects Library Reference  

Overview

About the Use a PageLayoutControl as an overview window Sample

[C#]

Overview.cs

using System;
using System.Windows.Forms;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS;


namespace Overview
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Overview : System.Windows.Forms.Form
	{
		public System.Windows.Forms.TextBox txbMxPath;
		public System.Windows.Forms.Button cmdLoadMxFile;
		public System.Windows.Forms.Button cmdZoomPage;
		public System.Windows.Forms.Label Label2;
		private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private ESRI.ArcGIS.Controls.AxPageLayoutControl axPageLayoutControl1;
		private ESRI.ArcGIS.Controls.AxPageLayoutControl axPageLayoutControl2;
		private ESRI.ArcGIS.Controls.AxLicenseControl axLicenseControl1;
        private IPageLayoutControl m_PageLayoutControl;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Overview()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
            //Release COM objects
            ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown();

			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Overview));
            this.txbMxPath = new System.Windows.Forms.TextBox();
            this.cmdLoadMxFile = new System.Windows.Forms.Button();
            this.cmdZoomPage = new System.Windows.Forms.Button();
            this.Label2 = new System.Windows.Forms.Label();
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.axPageLayoutControl1 = new ESRI.ArcGIS.Controls.AxPageLayoutControl();
            this.axPageLayoutControl2 = new ESRI.ArcGIS.Controls.AxPageLayoutControl();
            this.axLicenseControl1 = new ESRI.ArcGIS.Controls.AxLicenseControl();
            ((System.ComponentModel.ISupportInitialize)(this.axPageLayoutControl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.axPageLayoutControl2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit();
            this.SuspendLayout();
            // 
            // txbMxPath
            // 
            this.txbMxPath.AcceptsReturn = true;
            this.txbMxPath.BackColor = System.Drawing.SystemColors.Window;
            this.txbMxPath.Cursor = System.Windows.Forms.Cursors.IBeam;
            this.txbMxPath.Enabled = false;
            this.txbMxPath.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txbMxPath.ForeColor = System.Drawing.SystemColors.WindowText;
            this.txbMxPath.Location = new System.Drawing.Point(8, 8);
            this.txbMxPath.MaxLength = 0;
            this.txbMxPath.Name = "txbMxPath";
            this.txbMxPath.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.txbMxPath.Size = new System.Drawing.Size(249, 19);
            this.txbMxPath.TabIndex = 6;
            // 
            // cmdLoadMxFile
            // 
            this.cmdLoadMxFile.BackColor = System.Drawing.SystemColors.Control;
            this.cmdLoadMxFile.Cursor = System.Windows.Forms.Cursors.Default;
            this.cmdLoadMxFile.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdLoadMxFile.ForeColor = System.Drawing.SystemColors.ControlText;
            this.cmdLoadMxFile.Location = new System.Drawing.Point(264, 8);
            this.cmdLoadMxFile.Name = "cmdLoadMxFile";
            this.cmdLoadMxFile.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cmdLoadMxFile.Size = new System.Drawing.Size(113, 25);
            this.cmdLoadMxFile.TabIndex = 5;
            this.cmdLoadMxFile.Text = "Load Mx File";
            this.cmdLoadMxFile.UseVisualStyleBackColor = false;
            this.cmdLoadMxFile.Click += new System.EventHandler(this.cmdLoadMxFile_Click);
            // 
            // cmdZoomPage
            // 
            this.cmdZoomPage.BackColor = System.Drawing.SystemColors.Control;
            this.cmdZoomPage.Cursor = System.Windows.Forms.Cursors.Default;
            this.cmdZoomPage.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdZoomPage.ForeColor = System.Drawing.SystemColors.ControlText;
            this.cmdZoomPage.Location = new System.Drawing.Point(264, 320);
            this.cmdZoomPage.Name = "cmdZoomPage";
            this.cmdZoomPage.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cmdZoomPage.Size = new System.Drawing.Size(113, 25);
            this.cmdZoomPage.TabIndex = 9;
            this.cmdZoomPage.Text = "Zoom To Page";
            this.cmdZoomPage.UseVisualStyleBackColor = false;
            this.cmdZoomPage.Click += new System.EventHandler(this.cmdZoomPage_Click);
            // 
            // Label2
            // 
            this.Label2.BackColor = System.Drawing.SystemColors.Control;
            this.Label2.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Label2.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label2.Location = new System.Drawing.Point(264, 256);
            this.Label2.Name = "Label2";
            this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label2.Size = new System.Drawing.Size(121, 57);
            this.Label2.TabIndex = 10;
            this.Label2.Text = "Use the left mouse button to drag a rectangle and  the right mouse button to pan." +
                "";
            // 
            // axPageLayoutControl1
            // 
            this.axPageLayoutControl1.Location = new System.Drawing.Point(8, 32);
            this.axPageLayoutControl1.Name = "axPageLayoutControl1";
            this.axPageLayoutControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axPageLayoutControl1.OcxState")));
            this.axPageLayoutControl1.Size = new System.Drawing.Size(248, 320);
            this.axPageLayoutControl1.TabIndex = 11;
            this.axPageLayoutControl1.OnMouseDown += new ESRI.ArcGIS.Controls.IPageLayoutControlEvents_Ax_OnMouseDownEventHandler(this.axPageLayoutControl1_OnMouseDown);
            this.axPageLayoutControl1.OnPageLayoutReplaced += new ESRI.ArcGIS.Controls.IPageLayoutControlEvents_Ax_OnPageLayoutReplacedEventHandler(this.axPageLayoutControl1_OnPageLayoutReplaced);
            this.axPageLayoutControl1.OnExtentUpdated += new ESRI.ArcGIS.Controls.IPageLayoutControlEvents_Ax_OnExtentUpdatedEventHandler(this.axPageLayoutControl1_OnExtentUpdated);
            // 
            // axPageLayoutControl2
            // 
            this.axPageLayoutControl2.Location = new System.Drawing.Point(264, 40);
            this.axPageLayoutControl2.Name = "axPageLayoutControl2";
            this.axPageLayoutControl2.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axPageLayoutControl2.OcxState")));
            this.axPageLayoutControl2.Size = new System.Drawing.Size(112, 176);
            this.axPageLayoutControl2.TabIndex = 12;
            // 
            // axLicenseControl1
            // 
            this.axLicenseControl1.Enabled = true;
            this.axLicenseControl1.Location = new System.Drawing.Point(24, 48);
            this.axLicenseControl1.Name = "axLicenseControl1";
            this.axLicenseControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axLicenseControl1.OcxState")));
            this.axLicenseControl1.Size = new System.Drawing.Size(32, 32);
            this.axLicenseControl1.TabIndex = 13;
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(384, 358);
            this.Controls.Add(this.axLicenseControl1);
            this.Controls.Add(this.axPageLayoutControl2);
            this.Controls.Add(this.axPageLayoutControl1);
            this.Controls.Add(this.cmdZoomPage);
            this.Controls.Add(this.Label2);
            this.Controls.Add(this.txbMxPath);
            this.Controls.Add(this.cmdLoadMxFile);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.axPageLayoutControl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.axPageLayoutControl2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
            
            if (!RuntimeManager.Bind(ProductCode.Engine))
            {
                if (!RuntimeManager.Bind(ProductCode.Desktop))
                {
                    MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
                    return;
                }
            }
            Application.Run(new Overview());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			m_PageLayoutControl = (IPageLayoutControl) axPageLayoutControl2.Object;

			//Set PageLayoutControl properties
			axPageLayoutControl1.Enabled = true;
			m_PageLayoutControl.Enabled = false;
			axPageLayoutControl1.Appearance = esriControlsAppearance.esri3D;
			m_PageLayoutControl.Appearance = esriControlsAppearance.esriFlat;
			axPageLayoutControl1.BorderStyle = esriControlsBorderStyle.esriBorder;
			m_PageLayoutControl.BorderStyle = esriControlsBorderStyle.esriNoBorder;
		}

		private void cmdLoadMxFile_Click(object sender, System.EventArgs e)
		{
			//Open a file dialog for selecting map documents
			openFileDialog1.Title = "Browse Map Document";
			openFileDialog1.Filter = "Map Documents (*.mxd)|*.mxd";
			openFileDialog1.ShowDialog();

			//Exit if no map document is selected
			string sFilePath = openFileDialog1.FileName;
			if (sFilePath == "") return;

			//Validate and load the Mx document
			if (axPageLayoutControl1.CheckMxFile(sFilePath))
			{
				txbMxPath.Text = sFilePath;
				axPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
				axPageLayoutControl1.LoadMxFile(sFilePath,Type.Missing);
				axPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
			}
			else
			{
				MessageBox.Show(sFilePath + " is not a valid ArcMap document");
			}
		}

		private void cmdZoomPage_Click(object sender, System.EventArgs e)
		{
			//Zoom to the whole page
			axPageLayoutControl1.ZoomToWholePage();

			//Get the IElement interface by finding an element by its name
			IElement element = m_PageLayoutControl.FindElementByName("ZoomExtent", 1);
			if (element != null)
			{
				//Delete the element
				m_PageLayoutControl.GraphicsContainer.DeleteElement(element);
				//Refresh the graphics
				m_PageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics,Type.Missing, Type.Missing);
			}
		}

		private void axPageLayoutControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent e)
		{
			//Zoom in
			if (e.button == 1)
			{
				axPageLayoutControl1.Extent = axPageLayoutControl1.TrackRectangle();
			}
				//Pan
			else if (e.button == 2)
			{
				axPageLayoutControl1.Pan();
			}
		}

		private void axPageLayoutControl1_OnPageLayoutReplaced(object sender, ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnPageLayoutReplacedEvent e)
		{
			//Get the file path
			string sFilePath = txbMxPath.Text;
			//Validate and load the Mx document
			if (m_PageLayoutControl.CheckMxFile(sFilePath))
			{
				m_PageLayoutControl.LoadMxFile(sFilePath,Type.Missing);
			}
		}

        private void axPageLayoutControl1_OnExtentUpdated(object sender, IPageLayoutControlEvents_OnExtentUpdatedEvent e)
        {
            //QI for IEnvelope
            IEnvelope envelope = (IEnvelope)e.newEnvelope;

            //Get the IElement interface by finding an element by its name 
            IElement element = m_PageLayoutControl.FindElementByName("ZoomExtent", 1);
            if (element != null)
            {
                //Delete the graphic
                m_PageLayoutControl.GraphicsContainer.DeleteElement(element);
            }
            element = new RectangleElementClass();

            //Get the IRGBColor interface
            IRgbColor color = new RgbColorClass();
            //Set the color properties
            color.RGB = 255;
            color.Transparency = 255;

            //Get the ILine symbol interface
            ILineSymbol outline = new SimpleLineSymbolClass();
            //Set the line symbol properties
            outline.Width = 10;
            outline.Color = color;

            //Set the color properties
            color = new RgbColorClass();
            color.RGB = 255;
            color.Transparency = 0;

            //Get the IFillSymbol properties
            IFillSymbol fillSymbol = new SimpleFillSymbolClass();
            //Set the fill symbol properties
            fillSymbol.Color = color;
            fillSymbol.Outline = outline;

            //QI for IFillShapeElement interface through the IElement interface
            IFillShapeElement fillShapeElement = (IFillShapeElement)element;
            //Set the symbol property
            fillShapeElement.Symbol = fillSymbol;

            //Add the element
            m_PageLayoutControl.AddElement(element, e.newEnvelope, Type.Missing, "ZoomExtent", -1);
            //Refresh the graphics
            m_PageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, Type.Missing, Type.Missing);
        }

	}
}

[Visual Basic .NET]

Overview.vb

Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.SystemUI
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Display
Imports ESRI.ArcGIS.Geometry
Imports ESRI.ArcGIS.Controls
Imports ESRI.ArcGIS


Public Class Form1
    Inherits System.Windows.Forms.Form

    <STAThread()> _
Shared Sub Main()

        'Load runtime 
        If Not RuntimeManager.Bind(ProductCode.Engine) Then
            If Not RuntimeManager.Bind(ProductCode.Desktop) Then
                MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.")
                System.Environment.Exit(1) ' Force exit or other indication in the application
            End If
        End If
        Application.Run(New Form1())
    End Sub
#Region "Windows Form Designer generated code "
    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()
    End Sub
    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
        'Release COM objects
        ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown()

        If Disposing Then
            If Not components Is Nothing Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(Disposing)
    End Sub
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
    Public WithEvents txbMxPath As System.Windows.Forms.TextBox
    Public WithEvents cmdLoadMxFile As System.Windows.Forms.Button
    Public WithEvents cmdZoomPage As System.Windows.Forms.Button
    Public WithEvents Label2 As System.Windows.Forms.Label
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents AxPageLayoutControl1 As ESRI.ArcGIS.Controls.AxPageLayoutControl
    Friend WithEvents AxPageLayoutControl2 As ESRI.ArcGIS.Controls.AxPageLayoutControl
    Friend WithEvents AxLicenseControl1 As ESRI.ArcGIS.Controls.AxLicenseControl
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.txbMxPath = New System.Windows.Forms.TextBox
        Me.cmdLoadMxFile = New System.Windows.Forms.Button
        Me.cmdZoomPage = New System.Windows.Forms.Button
        Me.Label2 = New System.Windows.Forms.Label
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.AxPageLayoutControl1 = New ESRI.ArcGIS.Controls.AxPageLayoutControl
        Me.AxPageLayoutControl2 = New ESRI.ArcGIS.Controls.AxPageLayoutControl
        Me.AxLicenseControl1 = New ESRI.ArcGIS.Controls.AxLicenseControl
        CType(Me.AxPageLayoutControl1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.AxPageLayoutControl2, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'txbMxPath
        '
        Me.txbMxPath.AcceptsReturn = True
        Me.txbMxPath.AutoSize = False
        Me.txbMxPath.BackColor = System.Drawing.SystemColors.Window
        Me.txbMxPath.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.txbMxPath.Enabled = False
        Me.txbMxPath.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.txbMxPath.ForeColor = System.Drawing.SystemColors.WindowText
        Me.txbMxPath.Location = New System.Drawing.Point(8, 8)
        Me.txbMxPath.MaxLength = 0
        Me.txbMxPath.Name = "txbMxPath"
        Me.txbMxPath.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.txbMxPath.Size = New System.Drawing.Size(249, 19)
        Me.txbMxPath.TabIndex = 4
        Me.txbMxPath.Text = ""
        '
        'cmdLoadMxFile
        '
        Me.cmdLoadMxFile.BackColor = System.Drawing.SystemColors.Control
        Me.cmdLoadMxFile.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdLoadMxFile.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdLoadMxFile.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdLoadMxFile.Location = New System.Drawing.Point(264, 5)
        Me.cmdLoadMxFile.Name = "cmdLoadMxFile"
        Me.cmdLoadMxFile.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdLoadMxFile.Size = New System.Drawing.Size(113, 25)
        Me.cmdLoadMxFile.TabIndex = 3
        Me.cmdLoadMxFile.Text = "Load Mx File"
        '
        'cmdZoomPage
        '
        Me.cmdZoomPage.BackColor = System.Drawing.SystemColors.Control
        Me.cmdZoomPage.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdZoomPage.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdZoomPage.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdZoomPage.Location = New System.Drawing.Point(264, 328)
        Me.cmdZoomPage.Name = "cmdZoomPage"
        Me.cmdZoomPage.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdZoomPage.Size = New System.Drawing.Size(113, 25)
        Me.cmdZoomPage.TabIndex = 2
        Me.cmdZoomPage.Text = "Zoom To Page"
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.SystemColors.Control
        Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label2.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label2.Location = New System.Drawing.Point(264, 264)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(121, 57)
        Me.Label2.TabIndex = 5
        Me.Label2.Text = "Use the left mouse button to drag a rectangle and  the right mouse button to pan." & _
        ""
        '
        'AxPageLayoutControl1
        '
        Me.AxPageLayoutControl1.Location = New System.Drawing.Point(8, 32)
        Me.AxPageLayoutControl1.Name = "AxPageLayoutControl1"
        Me.AxPageLayoutControl1.OcxState = CType(resources.GetObject("AxPageLayoutControl1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxPageLayoutControl1.Size = New System.Drawing.Size(248, 320)
        Me.AxPageLayoutControl1.TabIndex = 6
        '
        'AxPageLayoutControl2
        '
        Me.AxPageLayoutControl2.Location = New System.Drawing.Point(264, 40)
        Me.AxPageLayoutControl2.Name = "AxPageLayoutControl2"
        Me.AxPageLayoutControl2.OcxState = CType(resources.GetObject("AxPageLayoutControl2.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxPageLayoutControl2.Size = New System.Drawing.Size(120, 184)
        Me.AxPageLayoutControl2.TabIndex = 7
        '
        'AxLicenseControl1
        '
        Me.AxLicenseControl1.Enabled = True
        Me.AxLicenseControl1.Location = New System.Drawing.Point(32, 48)
        Me.AxLicenseControl1.Name = "AxLicenseControl1"
        Me.AxLicenseControl1.OcxState = CType(resources.GetObject("AxLicenseControl1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxLicenseControl1.Size = New System.Drawing.Size(200, 50)
        Me.AxLicenseControl1.TabIndex = 8
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(387, 362)
        Me.Controls.Add(Me.AxLicenseControl1)
        Me.Controls.Add(Me.AxPageLayoutControl2)
        Me.Controls.Add(Me.AxPageLayoutControl1)
        Me.Controls.Add(Me.txbMxPath)
        Me.Controls.Add(Me.cmdLoadMxFile)
        Me.Controls.Add(Me.cmdZoomPage)
        Me.Controls.Add(Me.Label2)
        Me.Cursor = System.Windows.Forms.Cursors.Default
        Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Location = New System.Drawing.Point(4, 23)
        Me.Name = "Form1"
        Me.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Text = "Overview"
        CType(Me.AxPageLayoutControl1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.AxPageLayoutControl2, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
#End Region

    Private m_pPageLayoutControl As IPageLayoutControl

    Private Sub cmdLoadMxFile_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLoadMxFile.Click

        'Open a file dialog for selecting map documents
        OpenFileDialog1.Title = "Browse Map Document"
        OpenFileDialog1.Filter = "Map Documents (*.mxd)|*.mxd"
        OpenFileDialog1.ShowDialog()

        'Exit if no map document is selected
        Dim sFilePath As String
        sFilePath = OpenFileDialog1.FileName
        If sFilePath = "" Then Exit Sub

        'Validate and load the Mx document
        If AxPageLayoutControl1.CheckMxFile(sFilePath) Then
            txbMxPath.Text = sFilePath
            AxPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass
            AxPageLayoutControl1.LoadMxFile(sFilePath)
            AxPageLayoutControl1.MousePointer = esriControlsMousePointer.esriPointerDefault
        Else
            MsgBox(sFilePath & " is not a valid ArcMap document")
        End If

    End Sub

    Private Sub cmdZoomPage_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdZoomPage.Click

        'Zoom to the whole page
        AxPageLayoutControl1.ZoomToWholePage()

        'Get the IElement interface by finding an element by its name
        Dim pElement As IElement
        pElement = m_pPageLayoutControl.FindElementByName("ZoomExtent")
        If Not pElement Is Nothing Then
            'Delete the element
            m_pPageLayoutControl.GraphicsContainer.DeleteElement(pElement)
            'Refresh the graphics
            m_pPageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics)
        End If

    End Sub

    Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load

        m_pPageLayoutControl = AxPageLayoutControl2.Object

        'Set PageLayoutControl properties
        AxPageLayoutControl1.Enabled = True
        m_pPageLayoutControl.Enabled = False
        AxPageLayoutControl1.Appearance = esriControlsAppearance.esri3D
        m_pPageLayoutControl.Appearance = esriControlsAppearance.esriFlat
        AxPageLayoutControl1.BorderStyle = esriControlsBorderStyle.esriBorder
        m_pPageLayoutControl.BorderStyle = esriControlsBorderStyle.esriNoBorder

    End Sub

    Private Sub AxPageLayoutControl1_OnExtentUpdated(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnExtentUpdatedEvent) Handles AxPageLayoutControl1.OnExtentUpdated
        'QI for IEnvelope
        Dim pEnvelope As IEnvelope
        pEnvelope = e.newEnvelope

        'Get the IElement interface by finding an element by its name
        Dim pElement As IElement
        pElement = m_pPageLayoutControl.FindElementByName("ZoomExtent")
        If Not pElement Is Nothing Then
            'Delete the graphic
            m_pPageLayoutControl.GraphicsContainer.DeleteElement(pElement)
        End If
        pElement = New RectangleElementClass

        'Get the IRGBColor interface
        Dim pColor As IRgbColor
        pColor = New RgbColorClass
        'Set the color properties
        pColor.RGB = 255
        pColor.Transparency = 255

        'Get the ILine symbol interface
        Dim pOutline As ILineSymbol
        pOutline = New SimpleLineSymbolClass
        'Set the line symbol properties
        pOutline.Width = 10
        pOutline.Color = pColor

        'Set the color properties
        pColor = New RgbColorClass
        pColor.RGB = 255
        pColor.Transparency = 0

        'Get the IFillSymbol properties
        Dim pFillSymbol As IFillSymbol
        pFillSymbol = New SimpleFillSymbolClass
        'Set the fill symbol properties
        pFillSymbol.Color = pColor
        pFillSymbol.Outline = pOutline

        'QI for IFillShapeElement interface through the IElement interface
        Dim pFillShapeElement As IFillShapeElement
        pFillShapeElement = pElement
        'Set the symbol property
        pFillShapeElement.Symbol = pFillSymbol

        'Add the element
        m_pPageLayoutControl.AddElement(pElement, e.newEnvelope, , "ZoomExtent")
        'Refresh the graphics
        m_pPageLayoutControl.Refresh(esriViewDrawPhase.esriViewGraphics, Nothing, Nothing)

    End Sub

    Private Sub AxPageLayoutControl1_OnMouseDown(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnMouseDownEvent) Handles AxPageLayoutControl1.OnMouseDown
        'Zoom in
        If e.button = 1 Then
            AxPageLayoutControl1.Extent = AxPageLayoutControl1.TrackRectangle
            'Pan
        ElseIf e.button = 2 Then
            AxPageLayoutControl1.Pan()
        End If
    End Sub

    Private Sub AxPageLayoutControl1_OnPageLayoutReplaced(ByVal sender As Object, ByVal e As ESRI.ArcGIS.Controls.IPageLayoutControlEvents_OnPageLayoutReplacedEvent) Handles AxPageLayoutControl1.OnPageLayoutReplaced
        'Get the file path
        Dim sFilePath As String
        sFilePath = txbMxPath.Text
        'Validate and load the Mx document
        If m_pPageLayoutControl.CheckMxFile(sFilePath) Then
            m_pPageLayoutControl.LoadMxFile((sFilePath))
        End If
    End Sub
End Class