转载请注明出处,谢谢!
首页保证先安装了IDL7.0环境。打开VS2008,新建C#项目,然后在工具箱中右键,选择项,找到COM组件中的IDLDrawWidget Control,打上勾。如图:

确定后工具箱中就会多出一个工具,将其拖放到窗体上

双击窗体,写窗体生成时的初始化IDL代码:
private void Form1_Load(object sender, EventArgs e)
{
int n;
axIDLDrawWidget1.IdlPath = @"D:\Program Files\IDL7\IDL70\bin\bin.x86\idl.dll";
n = axIDLDrawWidget1.InitIDL((int)this.Handle);
if (n == 0)
{
MessageBox.Show("IDL控件初始化失败");
}
}
其中
D:\Program Files\IDL7\IDL70\bin\bin.x86\idl.dll 是自己安装IDL时的路径。待会我们提取相应的dll后就可以改掉这个路径。然后我们写一个运行IDL命令的函数,如下:
public int IDLEstr(string cmdstr)
{
int n;
n = axIDLDrawWidget1.ExecuteStr(cmdstr);
return n;
}
然后我们放一个按钮,写上运行我们事先生成好的sav文件的代码:
private void button2_Click(object sender, EventArgs e)
{
string cmd = "@print";
IDLEstr("Restore,'print.sav'");//编译程序
IDLEstr(cmd);
}
其中print.pro的代码如图:

生成sav文件的方法如图:

生成好sav文件后将sav文件考到我们的项目文件夹下面,与我们的exe文件在一起。
然后我们再放一个文本框,一个按钮,按钮事件写上运行文本框里面的IDL命令,代码如下:
private void button1_Click(object sender, EventArgs e)
{
IDLEstr(textBox1.Text.ToString().Trim());
}
OK,到这里就可以运行我们的程序了,如图:

下面我们装提取我们程序所须要的IDL系统文件,使程序脱离IDL环境也可以运行和使用。
提取其实很简单,到另一个环境去运行,然后程序提示少什么文件,就把什么文件拷过来就行了。我这里用另一种比较巧妙的方法。
我们运行我们的程序,然后到IDL系统目录bin.x86下面,也就是idl.dll文件所在的文件夹,然后我们全选,按删除键,确定删除,这时系统会提示有些文件不能被删掉,因为正在被我们的程序所使用,那么这些没能删掉的文件就是我们程序所须要的东西了,我们把它们拷出来。
照如此方法,相应也可发现我们还须要resource/fonts/hersh1.chr文件,还有就是licence/licence.dat文件。
最后列出所有须要文件的结构。
.exe .sav AxInterop.IDLDRAWX3Lib.dll Interop.IDLDRAWX3Lib.dll IDL\include\bin.x86\freetype2_1_3.dll IDL\include\bin.x86\gl_driver.dll IDL\include\bin.x86\idl.dll IDL\include\bin.x86\MesaGL6_2.dll IDL\include\bin.x86\MesaGLU6_2.dll IDL\include\bin.x86\osmesa6_2.dll IDL\include\bin.x86\ug3220.dll IDL\resource\fonts\hersh1.chr IDL\license.dat

最后程序完整代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace IDLTest1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int n;
//axIDLDrawWidget1.IdlPath = @"D:\Program Files\IDL7\IDL70\bin\bin.x86\idl.dll";
axIDLDrawWidget1.IdlPath = @"IDL\include\bin.x86\idl.dll";
n = axIDLDrawWidget1.InitIDL((int)this.Handle);
if (n == 0)
{
MessageBox.Show("IDL控件初始化失败");
}
}
public int IDLEstr(string cmdstr)
{
int n;
n = axIDLDrawWidget1.ExecuteStr(cmdstr);
return n;
}
private void button1_Click(object sender, EventArgs e)
{
IDLEstr(textBox1.Text.ToString().Trim());
}
private void button2_Click(object sender, EventArgs e)
{
string cmd = "@print";
IDLEstr("Restore,'print.sav'");//编译程序
IDLEstr(cmd);
}
}
}