edcoder

在中篇我们讲到使用OpenFileDialog控件可以添加shp文件。(最简单的ArcGIS Engine应用程序(中)

添加lyr文件的操作也是大同小异的。

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;

namespace SimpleArcEngineDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void menuAddLyr_Click(object sender, EventArgs e)
        {
            //步骤1: 打开文件对话框浏览到一个具体lyr文件。
            
            //文件过滤器, 选择后缀名为.lyr
            openFileDialog1.Filter = "lyr文件(*.lyr)|*.lyr";
            
            //设定文件对话框的初始化路径
            openFileDialog1.InitialDirectory = @"D:\data";
            
            openFileDialog1.Multiselect = false; //不允许多选
            DialogResult pDialogResult = openFileDialog1.ShowDialog(); //打开对话框
            if (pDialogResult != DialogResult.OK)
            {
                return; //用户没有选择时返回
            }
            string pFileName = openFileDialog1.FileName; //得到完整的路径(路径+文件名)

            //步骤2: 通过地图控件的方法(AddLayerFromFile)直接加载。
            axMapControl1.AddLayerFromFile(pFileName);
            axMapControl1.ActiveView.Refresh();
} } }

 

简述:

单机“添加lyr”,会弹出一个打开文件的对话框,浏览目录后选择任意一个lyr文件,单机确定,即可将指定的lyr文件加载到地图控件当中。

 

谢谢观看!本人初学GIS二次开发,如果有不对的地方,请多多包涵!

 

分类:

技术点:

相关文章:

  • 2021-05-31
  • 2021-12-26
  • 2021-09-29
  • 2021-04-24
  • 2021-06-08
  • 2022-01-09
  • 2021-09-04
  • 2021-06-09
猜你喜欢
  • 2021-12-27
  • 2021-11-23
  • 2021-10-17
  • 2021-05-20
  • 2021-08-27
  • 2021-12-02
  • 2021-07-28
  • 2021-04-23
相关资源
相似解决方案