private void button2_Click(object sender, EventArgs e)
{
string[] addshp = openshapefile();//定义一个数组变量addshp用来接收函数的返回值
axMapControl1.AddShapeFile(addshp[0],addshp[1]);
}
public string[] openshapefile()
{
string[] shpfile = new string[2];
OpenFileDialog OpenShpFile = new OpenFileDialog();
OpenShpFile.Title = "打开shp文件";
OpenShpFile.InitialDirectory = @"I:\Cstudy\data\图件";
OpenShpFile.Filter = "shp文件(*.shp)|*.shp";
if (OpenShpFile.ShowDialog() == DialogResult.OK)
{
string ShaPath = OpenShpFile.FileName;
int Position = ShaPath.LastIndexOf("\\");
string FilePath = ShaPath.Substring(0, Position);
string ShpName = ShaPath.Substring(Position+1);
shpfile[0] = FilePath;
shpfile[1] = ShpName;
}
return shpfile;
}
}