可能是妳的 openFileDialog2控件沒有選中任何文件的原因。
妳可以用壹個
If( openFileDialog2.showDialog()=DialogResult.OK)判斷用戶是否選擇文件之後再執行下面的代碼。
可以這樣修改妳的代碼
if(openFileDialog2.showDialog()==DialogResult.OK)
{
string FilePath = openFileDialog2.FileName;
if (axMapControl1.CheckMxFile(FilePath))
{
axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerHourglass;
axMapControl1.LoadMxFile(FilePath, 0, Type.Missing);
axMapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerDefault;
}
else
{
MessageBox.Show(FilePath+"is not a vaild ArcMap document");
return;
}
}
else
{
MessageBox.Show("沒有找到任何文件");
}