⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapcontrolmaptips.cs

📁 ui form windows csharp
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Define;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.SystemUI;


namespace UI
{
    public partial class MapControlMapTips : UserControl, InterfaceList
    {
        public MapControlMapTips()
        {
            InitializeComponent();
        }
        #region InterfaceList 成员
        public void RefreshData()
        {
           
        }
 
        #endregion

        private void button1_Click(object sender, EventArgs e)
        {
            this.openFileDialog1.Title = "打开";
            this.openFileDialog1.Filter = "MXD Files(*.mxd)|*.mxd|All Files(*.*)|*.*";
            this.openFileDialog1.RestoreDirectory = true;
            string sFileName="";

            if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                sFileName = this.openFileDialog1.FileName;
                if (sFileName.Length == 0)
                {
                    return;
                }
            }
            if (this.axMapControl1.CheckMxFile(sFileName))
            {
                this.axMapControl1.LoadMxFile(sFileName);
                this.axMapControl1.Enabled = true;
            }
            else
            {
                MessageBox.Show(sFileName + " is not a valid ArcMap document");
                return;
            }
            this.comboBox1.Items.Clear();
            for (int i = 0; i <= axMapControl1.LayerCount - 1; i++)
            {
                this.comboBox1.Items.Insert(i, axMapControl1.get_Layer(i).Name);
            }
            this.comboBox1.SelectedIndex = 0;
            //Enable controls if disabled
            if (this.checkBox1.Enabled == false) this.checkBox1.Enabled = true;
            if (this.checkBox2.Enabled == false) this.checkBox2.Enabled = true;
            if (this.comboBox1.Enabled == false) this.comboBox1.Enabled = true;
            if (this.comboBox2.Enabled == false) this.comboBox2.Enabled = true;

        }
        private void ShowLayerTips()
        {
            for (int i = 0; i < this.axMapControl1.LayerCount; i++)
            {
                ILayer layer = this.axMapControl1.get_Layer(i);
   
                    if (this.checkBox1.CheckState == CheckState.Checked)
                    {
                        layer.ShowTips = true;
                    }
                    else
                    {
                        layer.ShowTips = false;
                    }

            }


        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.axMapControl1.get_Layer(this.comboBox1.SelectedIndex) is IFeatureLayer == false)
            {
                this.comboBox2.Items.Clear();
                this.comboBox2.Enabled = false;
                return;
            }

            IFeatureLayer featurelayer = (IFeatureLayer)this.axMapControl1.get_Layer(this.comboBox1.SelectedIndex);
            ILayerFields layerfield = (ILayerFields)featurelayer;
            int j = 0;
            this.comboBox1.Items.Clear();
            this.comboBox1.Enabled = true;
            for (int i = 0; i < layerfield.FieldCount; i++)
            {
                IField field = (IField)layerfield.get_Field(i);
                if (field.Type != esriFieldType.esriFieldTypeGeometry)
                {
                    this.comboBox2.Items.Add(field.Name );
                    if (field.Name  == featurelayer.DisplayField)
                    {
                        this.comboBox2.SelectedIndex  = j;
                    }
                    j += 1;
                }
            }
            ShowLayerTips();

        }

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

            }

        }

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

            }
        }

        private void axMapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            if (e.button == 1)
            {
                this.axMapControl1.Extent = this.axMapControl1.TrackRectangle();

            }
            else if (e.button == 2)
            {
                this.axMapControl1.Pan();
            }

        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                IFeatureLayer featurelayer = (IFeatureLayer)this.axMapControl1.get_Layer(this.comboBox1.SelectedIndex);
                ILayerFields layerfield = (ILayerFields)featurelayer;
                for (int i = 0; i < layerfield.FieldCount; i++)
                {
                    IField field = layerfield.get_Field(i);
                    if (field.Name == this.comboBox2.Text)
                    {
                        featurelayer.DisplayField = this.comboBox2.Text;
                        break;
                    }
                }
            }
            catch (Exception ee)
            {

            }

        }

        private void checkBox1_CheckStateChanged(object sender, EventArgs e)
        {
            ShowLayerTips();
        }

        private void cmdFullExtent_Click(object sender, EventArgs e)
        {
            this.axMapControl1.Extent = this.axMapControl1.FullExtent;
        }

        private void MapControlMapTips_Load(object sender, EventArgs e)
        {
            this.checkBox1.Enabled = false;
            this.checkBox2.Enabled = false;
            this.comboBox1.Enabled = false;
            this.comboBox2.Enabled = false;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -