这个简单:
private void AddShp(object sender, EventArgs e)
{
//利用文件对话框选择加载的shp文件路径
OpenFileDialog OpenFdlg = new OpenFileDialog();
OpenFdlg.Title = "选择shp文件";
OpenFdlg.Filter = "Shape格式文件(*.shp)|*.shp";
OpenFdlg.ShowDialog();
string strFileName = OpenFdlg.FileName;
if (strFileName == string.Empty)
{
return;
}
//将Shp文件的路径分割为路径和不带格式后缀的文件名
string pathName = System.IO.Path.GetDirectoryName(strFileName);
string fileName = System.IO.Path.GetFileNameWithoutExtension(strFileName);
下面两行为默认指定文件路径和文件名
//string pathName = @"E:\HiOS\DataSHP";
//string fileName = "River_X";
axMapControl1.AddShapeFile(pathName, fileName);
axMapControl1.Extent = axMapControl1.FullExtent;
}
private void AddShp(object sender, EventArgs e)
{
//利用文件对话框选择加载的shp文件路径
OpenFileDialog OpenFdlg = new OpenFileDialog();
OpenFdlg.Title = "选择shp文件";
OpenFdlg.Filter = "Shape格式文件(*.shp)|*.shp";
OpenFdlg.ShowDialog();
string strFileName = OpenFdlg.FileName;
if (strFileName == string.Empty)
{
return;
}
//将Shp文件的路径分割为路径和不带格式后缀的文件名
string pathName = System.IO.Path.GetDirectoryName(strFileName);
string fileName = System.IO.Path.GetFileNameWithoutExtension(strFileName);
下面两行为默认指定文件路径和文件名
//string pathName = @"E:\HiOS\DataSHP";
//string fileName = "River_X";
axMapControl1.AddShapeFile(pathName, fileName);
axMapControl1.Extent = axMapControl1.FullExtent;
}