加载mxd 在执行CheckMxFile方法的时候,报异常System.Windows.Forms.AxHost+InvalidActiveXStateException
新手 不知道为什么? 代码贴出来:
public partial class Form1 : Form
{
public System.Windows.Forms.OpenFileDialog openFileDialog1;
public ESRI.ArcGIS.Controls.AxMapControl axMapControl1; public Form1()
{
InitializeComponent();
} private void button1_Click_1(object sender, EventArgs e)
{
openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
axMapControl1 = new ESRI.ArcGIS.Controls.AxMapControl();
openFileDialog1.Title = "打开地图文档!";
openFileDialog1.Filter = "Map Documents (*.mxd)|*.mxd";
openFileDialog1.ShowDialog();
string mxFilePath = openFileDialog1.FileName;
if (mxFilePath == "")
{
return;
}
if (axMapControl1.CheckMxFile(mxFilePath) == true)
{
axMapControl1.LoadMxFile(mxFilePath, Type.Missing, "");
axMapControl1.Enabled = true;
}
else
{
MessageBox.Show(mxFilePath + " is not a valid ArcMap document");
return;
}
}
}
新手 不知道为什么? 代码贴出来:
public partial class Form1 : Form
{
public System.Windows.Forms.OpenFileDialog openFileDialog1;
public ESRI.ArcGIS.Controls.AxMapControl axMapControl1; public Form1()
{
InitializeComponent();
} private void button1_Click_1(object sender, EventArgs e)
{
openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
axMapControl1 = new ESRI.ArcGIS.Controls.AxMapControl();
openFileDialog1.Title = "打开地图文档!";
openFileDialog1.Filter = "Map Documents (*.mxd)|*.mxd";
openFileDialog1.ShowDialog();
string mxFilePath = openFileDialog1.FileName;
if (mxFilePath == "")
{
return;
}
if (axMapControl1.CheckMxFile(mxFilePath) == true)
{
axMapControl1.LoadMxFile(mxFilePath, Type.Missing, "");
axMapControl1.Enabled = true;
}
else
{
MessageBox.Show(mxFilePath + " is not a valid ArcMap document");
return;
}
}
}
2010-05-08 14:20
转自http://hi.baidu.com/chlinet/blog/item/7dde2a7fe9d2a40029388a6b.html引发类型为“System.Windows.Forms.AxHost+InvalidActiveXStateException”的异常 解决办法出现题目的异常,多是引用第三方控件引起的。在NEW时,需要初始化该对象。 AxESACTIVEXLib.AxESActiveX ax = new AxESACTIVEXLib.AxESActiveX(); ((System.ComponentModel.ISupportInitialize)(this.ax)).BeginInit();
this.Controls.Add(ax);
((System.ComponentModel.ISupportInitialize)(this.ax)).EndInit();这样就OK了。