ArcObjects Library Reference  

MapTips

About the Displaying MapTips in the MapControl Sample

[C#]

MapTips.cs

using System;
using System.Windows.Forms;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS;


namespace MapTips
{
	public class Form1 : System.Windows.Forms.Form
	{
		public System.Windows.Forms.CheckBox chkShowTips;
		public System.Windows.Forms.Button cmdLoadData;
		public System.Windows.Forms.ComboBox cboDataField;
		public System.Windows.Forms.ComboBox cboDataLayer;
		public System.Windows.Forms.Label Label2;
		public System.Windows.Forms.Label Label1;
		public System.Windows.Forms.Button cmdFullExtent;
		public System.Windows.Forms.Label Label3;
        private System.Windows.Forms.OpenFileDialog openFileDialog1;
		private ESRI.ArcGIS.Controls.AxMapControl axMapControl1;
		private ESRI.ArcGIS.Controls.AxLicenseControl axLicenseControl1;
        internal CheckBox chkTransparent;
		private System.ComponentModel.IContainer components;

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

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

		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(Form1));
            this.chkShowTips = new System.Windows.Forms.CheckBox();
            this.cmdLoadData = new System.Windows.Forms.Button();
            this.cboDataField = new System.Windows.Forms.ComboBox();
            this.cboDataLayer = new System.Windows.Forms.ComboBox();
            this.Label2 = new System.Windows.Forms.Label();
            this.Label1 = new System.Windows.Forms.Label();
            this.cmdFullExtent = new System.Windows.Forms.Button();
            this.Label3 = new System.Windows.Forms.Label();
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.axMapControl1 = new ESRI.ArcGIS.Controls.AxMapControl();
            this.axLicenseControl1 = new ESRI.ArcGIS.Controls.AxLicenseControl();
            this.chkTransparent = new System.Windows.Forms.CheckBox();
            ((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).BeginInit();
            this.SuspendLayout();
            // 
            // chkShowTips
            // 
            this.chkShowTips.BackColor = System.Drawing.SystemColors.Control;
            this.chkShowTips.Cursor = System.Windows.Forms.Cursors.Default;
            this.chkShowTips.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.chkShowTips.ForeColor = System.Drawing.SystemColors.ControlText;
            this.chkShowTips.Location = new System.Drawing.Point(8, 40);
            this.chkShowTips.Name = "chkShowTips";
            this.chkShowTips.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.chkShowTips.Size = new System.Drawing.Size(129, 25);
            this.chkShowTips.TabIndex = 10;
            this.chkShowTips.Text = "Show Map Tips";
            this.chkShowTips.UseVisualStyleBackColor = false;
            this.chkShowTips.CheckedChanged += new System.EventHandler(this.chkShowTips_CheckedChanged);
            this.chkShowTips.CheckStateChanged += new System.EventHandler(this.chkShowTips_CheckStateChanged);
            // 
            // cmdLoadData
            // 
            this.cmdLoadData.BackColor = System.Drawing.SystemColors.Control;
            this.cmdLoadData.Cursor = System.Windows.Forms.Cursors.Default;
            this.cmdLoadData.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdLoadData.ForeColor = System.Drawing.SystemColors.ControlText;
            this.cmdLoadData.Location = new System.Drawing.Point(8, 8);
            this.cmdLoadData.Name = "cmdLoadData";
            this.cmdLoadData.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cmdLoadData.Size = new System.Drawing.Size(113, 25);
            this.cmdLoadData.TabIndex = 9;
            this.cmdLoadData.Text = "Load Document...";
            this.cmdLoadData.UseVisualStyleBackColor = false;
            this.cmdLoadData.Click += new System.EventHandler(this.cmdLoadData_Click);
            // 
            // cboDataField
            // 
            this.cboDataField.BackColor = System.Drawing.SystemColors.Window;
            this.cboDataField.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboDataField.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cboDataField.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboDataField.Location = new System.Drawing.Point(176, 40);
            this.cboDataField.Name = "cboDataField";
            this.cboDataField.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboDataField.Size = new System.Drawing.Size(161, 22);
            this.cboDataField.TabIndex = 8;
            this.cboDataField.SelectedIndexChanged += new System.EventHandler(this.cboDataField_SelectedIndexChanged);
            // 
            // cboDataLayer
            // 
            this.cboDataLayer.BackColor = System.Drawing.SystemColors.Window;
            this.cboDataLayer.Cursor = System.Windows.Forms.Cursors.Default;
            this.cboDataLayer.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cboDataLayer.ForeColor = System.Drawing.SystemColors.WindowText;
            this.cboDataLayer.Location = new System.Drawing.Point(176, 16);
            this.cboDataLayer.Name = "cboDataLayer";
            this.cboDataLayer.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cboDataLayer.Size = new System.Drawing.Size(161, 22);
            this.cboDataLayer.TabIndex = 7;
            this.cboDataLayer.SelectedIndexChanged += new System.EventHandler(this.cboDataLayer_SelectedIndexChanged);
            // 
            // 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(136, 40);
            this.Label2.Name = "Label2";
            this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label2.Size = new System.Drawing.Size(33, 17);
            this.Label2.TabIndex = 12;
            this.Label2.Text = "Fields:";
            // 
            // Label1
            // 
            this.Label1.BackColor = System.Drawing.SystemColors.Control;
            this.Label1.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Label1.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label1.Location = new System.Drawing.Point(136, 16);
            this.Label1.Name = "Label1";
            this.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label1.Size = new System.Drawing.Size(41, 17);
            this.Label1.TabIndex = 11;
            this.Label1.Text = "Layers:";
            // 
            // cmdFullExtent
            // 
            this.cmdFullExtent.BackColor = System.Drawing.SystemColors.Control;
            this.cmdFullExtent.Cursor = System.Windows.Forms.Cursors.Default;
            this.cmdFullExtent.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.cmdFullExtent.ForeColor = System.Drawing.SystemColors.ControlText;
            this.cmdFullExtent.Location = new System.Drawing.Point(224, 365);
            this.cmdFullExtent.Name = "cmdFullExtent";
            this.cmdFullExtent.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.cmdFullExtent.Size = new System.Drawing.Size(113, 25);
            this.cmdFullExtent.TabIndex = 13;
            this.cmdFullExtent.Text = "Zoom to Full Extent";
            this.cmdFullExtent.UseVisualStyleBackColor = false;
            this.cmdFullExtent.Click += new System.EventHandler(this.cmdFullExtent_Click);
            // 
            // Label3
            // 
            this.Label3.BackColor = System.Drawing.SystemColors.Control;
            this.Label3.Cursor = System.Windows.Forms.Cursors.Default;
            this.Label3.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.Label3.ForeColor = System.Drawing.SystemColors.ControlText;
            this.Label3.Location = new System.Drawing.Point(8, 373);
            this.Label3.Name = "Label3";
            this.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.Label3.Size = new System.Drawing.Size(209, 17);
            this.Label3.TabIndex = 14;
            this.Label3.Text = "Left mouse button to zoomin, right to pan";
            // 
            // axMapControl1
            // 
            this.axMapControl1.Location = new System.Drawing.Point(8, 88);
            this.axMapControl1.Name = "axMapControl1";
            this.axMapControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMapControl1.OcxState")));
            this.axMapControl1.Size = new System.Drawing.Size(328, 272);
            this.axMapControl1.TabIndex = 15;
            this.axMapControl1.OnMouseDown += new ESRI.ArcGIS.Controls.IMapControlEvents2_Ax_OnMouseDownEventHandler(this.axMapControl1_OnMouseDown);
            // 
            // axLicenseControl1
            // 
            this.axLicenseControl1.Enabled = true;
            this.axLicenseControl1.Location = new System.Drawing.Point(300, 68);
            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 = 16;
            // 
            // chkTransparent
            // 
            this.chkTransparent.AutoSize = true;
            this.chkTransparent.Location = new System.Drawing.Point(8, 65);
            this.chkTransparent.Name = "chkTransparent";
            this.chkTransparent.Size = new System.Drawing.Size(106, 17);
            this.chkTransparent.TabIndex = 17;
            this.chkTransparent.Text = "Transparent Tips";
            this.chkTransparent.UseVisualStyleBackColor = true;
            this.chkTransparent.CheckedChanged += new System.EventHandler(this.chkTransparent_CheckedChanged);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(344, 400);
            this.Controls.Add(this.chkTransparent);
            this.Controls.Add(this.axLicenseControl1);
            this.Controls.Add(this.axMapControl1);
            this.Controls.Add(this.cmdFullExtent);
            this.Controls.Add(this.Label3);
            this.Controls.Add(this.chkShowTips);
            this.Controls.Add(this.cmdLoadData);
            this.Controls.Add(this.cboDataField);
            this.Controls.Add(this.cboDataLayer);
            this.Controls.Add(this.Label2);
            this.Controls.Add(this.Label1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.axMapControl1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.axLicenseControl1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

		}
		#endregion

		[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 Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			//Disable controls
			chkShowTips.Enabled = false;
            chkTransparent.Enabled = false;
			cboDataLayer.Enabled = false;
			cboDataField.Enabled = false;
		}

		private void cboDataLayer_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//Disable field combo if feature layer is not selected and exit
			if (axMapControl1.get_Layer(cboDataLayer.SelectedIndex) is IFeatureLayer == false)
			{
				cboDataField.Items.Clear();
				cboDataField.Enabled = false;
				return;
			}

			//Get IFeatureLayer interface
			IFeatureLayer featureLayer = (IFeatureLayer) axMapControl1.get_Layer(cboDataLayer.SelectedIndex);
			//Query interface for ILayerFields
			ILayerFields layerFields = (ILayerFields) featureLayer;

			int j = 0;
			cboDataField.Items.Clear();
			cboDataField.Enabled = true;
			//Loop through the fields
			for (int i = 0; i <= layerFields.FieldCount - 1; i++)
			{
				//Get IField interface
				IField field = layerFields.get_Field(i);
				//If the field is not the shape field
				if (field.Type != esriFieldType.esriFieldTypeGeometry)
				{
					//Add field name to the control
					cboDataField.Items.Insert(j, field.Name);
					//If the field name is the display field
					if (field.Name == featureLayer.DisplayField)
					{
						//Select the field name in the control
						cboDataField.SelectedIndex = j;
					}
					j = j + 1;
				}
			}
			ShowLayerTips();
		}

		private void chkShowTips_CheckStateChanged(object sender, System.EventArgs e)
		{
			ShowLayerTips();
		}

		private void cmdFullExtent_Click(object sender, System.EventArgs e)
		{
			//Zoom to full extent of data
			axMapControl1.Extent = axMapControl1.FullExtent;
		}

		private void cmdLoadData_Click(object sender, System.EventArgs e)
		{
			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 map document
			if (axMapControl1.CheckMxFile(sFilePath)== true)
			{
				axMapControl1.LoadMxFile(sFilePath,Type.Missing,"");
				//Enabled MapControl
				axMapControl1.Enabled = true;
			}
			else
			{
				MessageBox.Show(sFilePath + " is not a valid ArcMap document");
					return;
			}

			//Add the layer names to combo
			cboDataLayer.Items.Clear();
			for (int i = 0; i <= axMapControl1.LayerCount - 1; i++)
			{
				cboDataLayer.Items.Insert(i, axMapControl1.get_Layer(i).Name);
			}

			//Select first layer in control
			cboDataLayer.SelectedIndex = 0;
			//Enable controls if disabled
			if (chkShowTips.Enabled == false) chkShowTips.Enabled = true;
            if (chkTransparent.Enabled == false) chkTransparent.Enabled = true;
			if (cboDataLayer.Enabled == false) cboDataLayer.Enabled = true;
			if (cboDataField.Enabled == false) cboDataField.Enabled = true;
		}

		private void ShowLayerTips()
		{
			//Loop through the maps layers
			for (int i = 0; i <= axMapControl1.LayerCount - 1; i++)
			{
				//Get ILayer interface
				ILayer layer = axMapControl1.get_Layer(i);
				//If is the layer selected in the control
				if (cboDataLayer.SelectedIndex == i)
				{
					//If want to show map tips
					if (chkShowTips.CheckState == CheckState.Checked)
					{
						layer.ShowTips = true;
					}
					else
					{
						layer.ShowTips = false;
					}
				}
				else
				{
					layer.ShowTips = false;
				}
			}
		}

		private void cboDataField_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			//Get IFeatureLayer interface 
			IFeatureLayer featureLayer = (IFeatureLayer) axMapControl1.get_Layer(cboDataLayer.SelectedIndex);
			//Query interface for IlayerFields
			ILayerFields layerFields = (ILayerFields) featureLayer;

			//Loop through the fields
			for (int i = 0; i <= layerFields.FieldCount - 1; i++)
			{
				//Get IField interface
				IField field = layerFields.get_Field(i);
				//If the field name is the name selected in the control
				if (field.Name == cboDataField.Text)
				{
					//Set the field as the display field
					featureLayer.DisplayField = field.Name;
					break;
				}
			}
		}

		private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
		{
			//If left mouse button zoom in
			if (e.button == 1)
			{
				axMapControl1.Extent = axMapControl1.TrackRectangle();
			}
				//If right mouse button pan
			else if (e.button == 2)
			{
				axMapControl1.Pan();
			}
		}

        private void chkShowTips_CheckedChanged(object sender, EventArgs e)
        {
            if (chkShowTips.CheckState == CheckState.Checked)
                axMapControl1.ShowMapTips = true;
            else
                axMapControl1.ShowMapTips = false;
        }

        private void chkTransparent_CheckedChanged(object sender, EventArgs e)
        {
            if (chkTransparent.CheckState == CheckState.Checked)
                axMapControl1.TipStyle = esriTipStyle.esriTipStyleTransparent;
            else
                axMapControl1.TipStyle = esriTipStyle.esriTipStyleSolid;
        }

	}
}

[Visual Basic .NET]

MapTips.vb

Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.SystemUI
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Geodatabase
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("Application shutting down. Unable to bind to ArcGIS Engine runtime.")
                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 cmdFullExtent As System.Windows.Forms.Button
    Public WithEvents chkShowTips As System.Windows.Forms.CheckBox
    Public WithEvents cmdLoadData As System.Windows.Forms.Button
    Public WithEvents cboDataField As System.Windows.Forms.ComboBox
    Public WithEvents cboDataLayer As System.Windows.Forms.ComboBox
    Public WithEvents Label3 As System.Windows.Forms.Label
    Public WithEvents Label2 As System.Windows.Forms.Label
    Public WithEvents Label1 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 AxMapControl1 As ESRI.ArcGIS.Controls.AxMapControl
    Friend WithEvents chkTransparent As System.Windows.Forms.CheckBox
    Friend WithEvents AxLicenseControl1 As ESRI.ArcGIS.Controls.AxLicenseControl
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.cmdFullExtent = New System.Windows.Forms.Button
        Me.chkShowTips = New System.Windows.Forms.CheckBox
        Me.cmdLoadData = New System.Windows.Forms.Button
        Me.cboDataField = New System.Windows.Forms.ComboBox
        Me.cboDataLayer = New System.Windows.Forms.ComboBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.Label1 = New System.Windows.Forms.Label
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.AxMapControl1 = New ESRI.ArcGIS.Controls.AxMapControl
        Me.AxLicenseControl1 = New ESRI.ArcGIS.Controls.AxLicenseControl
        Me.chkTransparent = New System.Windows.Forms.CheckBox
        CType(Me.AxMapControl1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'cmdFullExtent
        '
        Me.cmdFullExtent.BackColor = System.Drawing.SystemColors.Control
        Me.cmdFullExtent.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdFullExtent.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdFullExtent.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdFullExtent.Location = New System.Drawing.Point(223, 400)
        Me.cmdFullExtent.Name = "cmdFullExtent"
        Me.cmdFullExtent.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdFullExtent.Size = New System.Drawing.Size(113, 25)
        Me.cmdFullExtent.TabIndex = 7
        Me.cmdFullExtent.Text = "Zoom to Full Extent"
        Me.cmdFullExtent.UseVisualStyleBackColor = False
        '
        'chkShowTips
        '
        Me.chkShowTips.BackColor = System.Drawing.SystemColors.Control
        Me.chkShowTips.Cursor = System.Windows.Forms.Cursors.Default
        Me.chkShowTips.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.chkShowTips.ForeColor = System.Drawing.SystemColors.ControlText
        Me.chkShowTips.Location = New System.Drawing.Point(8, 40)
        Me.chkShowTips.Name = "chkShowTips"
        Me.chkShowTips.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.chkShowTips.Size = New System.Drawing.Size(129, 25)
        Me.chkShowTips.TabIndex = 4
        Me.chkShowTips.Text = "Show Map Tips"
        Me.chkShowTips.UseVisualStyleBackColor = False
        '
        'cmdLoadData
        '
        Me.cmdLoadData.BackColor = System.Drawing.SystemColors.Control
        Me.cmdLoadData.Cursor = System.Windows.Forms.Cursors.Default
        Me.cmdLoadData.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cmdLoadData.ForeColor = System.Drawing.SystemColors.ControlText
        Me.cmdLoadData.Location = New System.Drawing.Point(8, 8)
        Me.cmdLoadData.Name = "cmdLoadData"
        Me.cmdLoadData.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cmdLoadData.Size = New System.Drawing.Size(113, 25)
        Me.cmdLoadData.TabIndex = 3
        Me.cmdLoadData.Text = "Load Document..."
        Me.cmdLoadData.UseVisualStyleBackColor = False
        '
        'cboDataField
        '
        Me.cboDataField.BackColor = System.Drawing.SystemColors.Window
        Me.cboDataField.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboDataField.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cboDataField.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboDataField.Location = New System.Drawing.Point(176, 40)
        Me.cboDataField.Name = "cboDataField"
        Me.cboDataField.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboDataField.Size = New System.Drawing.Size(161, 22)
        Me.cboDataField.TabIndex = 2
        '
        'cboDataLayer
        '
        Me.cboDataLayer.BackColor = System.Drawing.SystemColors.Window
        Me.cboDataLayer.Cursor = System.Windows.Forms.Cursors.Default
        Me.cboDataLayer.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.cboDataLayer.ForeColor = System.Drawing.SystemColors.WindowText
        Me.cboDataLayer.Location = New System.Drawing.Point(176, 16)
        Me.cboDataLayer.Name = "cboDataLayer"
        Me.cboDataLayer.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.cboDataLayer.Size = New System.Drawing.Size(161, 22)
        Me.cboDataLayer.TabIndex = 1
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.SystemColors.Control
        Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label3.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label3.Location = New System.Drawing.Point(7, 400)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(209, 17)
        Me.Label3.TabIndex = 8
        Me.Label3.Text = "Left mouse button to zoomin, right to pan"
        '
        '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(136, 42)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(33, 17)
        Me.Label2.TabIndex = 6
        Me.Label2.Text = "Fields:"
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.SystemColors.Control
        Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label1.Location = New System.Drawing.Point(136, 18)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(41, 17)
        Me.Label1.TabIndex = 5
        Me.Label1.Text = "Layers:"
        '
        'AxMapControl1
        '
        Me.AxMapControl1.Location = New System.Drawing.Point(8, 89)
        Me.AxMapControl1.Name = "AxMapControl1"
        Me.AxMapControl1.OcxState = CType(resources.GetObject("AxMapControl1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxMapControl1.Size = New System.Drawing.Size(328, 296)
        Me.AxMapControl1.TabIndex = 9
        '
        'AxLicenseControl1
        '
        Me.AxLicenseControl1.Enabled = True
        Me.AxLicenseControl1.Location = New System.Drawing.Point(304, 68)
        Me.AxLicenseControl1.Name = "AxLicenseControl1"
        Me.AxLicenseControl1.OcxState = CType(resources.GetObject("AxLicenseControl1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxLicenseControl1.Size = New System.Drawing.Size(32, 32)
        Me.AxLicenseControl1.TabIndex = 10
        '
        'chkTransparent
        '
        Me.chkTransparent.AutoSize = True
        Me.chkTransparent.Location = New System.Drawing.Point(8, 65)
        Me.chkTransparent.Name = "chkTransparent"
        Me.chkTransparent.Size = New System.Drawing.Size(108, 18)
        Me.chkTransparent.TabIndex = 11
        Me.chkTransparent.Text = "Transparent Tips"
        Me.chkTransparent.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.ClientSize = New System.Drawing.Size(350, 433)
        Me.Controls.Add(Me.chkTransparent)
        Me.Controls.Add(Me.AxLicenseControl1)
        Me.Controls.Add(Me.AxMapControl1)
        Me.Controls.Add(Me.cmdFullExtent)
        Me.Controls.Add(Me.chkShowTips)
        Me.Controls.Add(Me.cmdLoadData)
        Me.Controls.Add(Me.cboDataField)
        Me.Controls.Add(Me.cboDataLayer)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        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 = "Map Tips"
        CType(Me.AxMapControl1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.AxLicenseControl1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
#End Region

    Private Sub cboDataField_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboDataField.SelectedIndexChanged

        'Get IFeatureLayer interface
        Dim pFeatureLayer As IFeatureLayer
        pFeatureLayer = AxMapControl1.get_Layer(cboDataLayer.SelectedIndex)
        'Query interface for IlayerFields
        Dim pLayerFields As ILayerFields
        pLayerFields = pFeatureLayer

        Dim i As Integer
        Dim pField As IField
        'Loop through the fields
        For i = 0 To pLayerFields.FieldCount - 1
            'Get IField interface
            pField = pLayerFields.Field(i)
            'If the field name is the name selected in the control
            If pField.Name = cboDataField.Text Then
                'Set the field as the display field
                pFeatureLayer.DisplayField = pField.Name
                Exit For
            End If
        Next i

    End Sub

    Private Sub cboDataLayer_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cboDataLayer.SelectedIndexChanged

        'Disable field combo if feature layer is not selected and exit
        If Not TypeOf AxMapControl1.get_Layer(cboDataLayer.SelectedIndex) Is IFeatureLayer Then
            cboDataField.Items.Clear()
            cboDataField.Enabled = False
            Exit Sub
        End If

        'Get IFeatureLayer interface
        Dim pFeatureLayer As IFeatureLayer
        pFeatureLayer = AxMapControl1.get_Layer(cboDataLayer.SelectedIndex)
        'Query interface for ILayerFields
        Dim pLayerFields As ILayerFields
        pLayerFields = pFeatureLayer

        Dim i As Integer
        Dim j As Integer
        j = 0
        Dim pField As IField
        cboDataField.Items.Clear()
        cboDataField.Enabled = True
        'Loop through the fields
        For i = 0 To pLayerFields.FieldCount - 1
            'Get IField interface
            pField = pLayerFields.Field(i)
            'If the field is not the shape field
            If pField.Type <> esriFieldType.esriFieldTypeGeometry Then
                'Add field name to the control
                cboDataField.Items.Insert(j, pField.Name)
                'If the field name is the display field
                If pField.Name = pFeatureLayer.DisplayField Then
                    'Select the field name in the control
                    cboDataField.SelectedIndex = j
                End If
                j = j + 1
            End If
        Next i

        ShowLayerTips()

    End Sub

    Private Sub chkShowTips_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles chkShowTips.CheckStateChanged
        ShowLayerTips()
    End Sub

    Private Sub cmdFullExtent_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFullExtent.Click
        'Zoom to full extent of data
        AxMapControl1.Extent = AxMapControl1.FullExtent
    End Sub

    Private Sub cmdLoadData_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLoadData.Click

        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 map document
        If AxMapControl1.CheckMxFile(sFilePath) Then
            AxMapControl1.LoadMxFile(sFilePath)
            'Enabled MapControl
            AxMapControl1.Enabled = True
        Else
            MsgBox(sFilePath & " is not a valid ArcMap document")
            Exit Sub
        End If

        'Add the layer names to combo
        cboDataLayer.Items.Clear()
        Dim i As Short
        For i = 0 To AxMapControl1.LayerCount - 1
            cboDataLayer.Items.Insert(i, AxMapControl1.get_Layer(i).Name)
        Next i

        'Select first layer in control
        cboDataLayer.SelectedIndex = 0
        'Enable controls if disabled
        If chkShowTips.Enabled = False Then chkShowTips.Enabled = True
        If chkTransparent.Enabled = False Then chkTransparent.Enabled = True
        If cboDataLayer.Enabled = False Then cboDataLayer.Enabled = True
        If cboDataField.Enabled = False Then cboDataField.Enabled = True

    End Sub

    Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        'Disable controls
        chkShowTips.Enabled = False
        chkTransparent.Enabled = False
        cboDataLayer.Enabled = False
        cboDataField.Enabled = False
    End Sub

    Private Sub ShowLayerTips()

        Dim i As Integer
        Dim pLayer As ILayer

        'Loop through the maps layers
        For i = 0 To AxMapControl1.LayerCount - 1
            'Get ILayer interface
            pLayer = AxMapControl1.get_Layer(i)
            'If is the layer selected in the control
            If cboDataLayer.SelectedIndex = i Then
                'If want to show map tips
                If chkShowTips.CheckState = 1 Then
                    pLayer.ShowTips = True
                Else
                    pLayer.ShowTips = False
                End If
            Else
                pLayer.ShowTips = False
            End If
        Next i
    End Sub

    Private Overloads Sub AxMapControl1_OnMouseDown(ByVal sender As System.Object, ByVal e As ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent) Handles AxMapControl1.OnMouseDown
        'If left mouse button zoom in
        If e.button = 1 Then
            AxMapControl1.Extent = AxMapControl1.TrackRectangle
            'If right mouse button pan
        ElseIf e.button = 2 Then
            AxMapControl1.Pan()
        End If
    End Sub

    Private Sub chkShowTips_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkShowTips.CheckedChanged
        If chkShowTips.CheckState = CheckState.Checked Then
            AxMapControl1.ShowMapTips = True
        Else
            AxMapControl1.ShowMapTips = False
        End If
    End Sub

    Private Sub chkTransparent_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTransparent.CheckedChanged
        If chkTransparent.CheckState = CheckState.Checked Then
            AxMapControl1.TipStyle = esriTipStyle.esriTipStyleTransparent
        Else
            AxMapControl1.TipStyle = esriTipStyle.esriTipStyleSolid
        End If
    End Sub
End Class