c#怎么设置一个按钮,点击就运行pro。c#读取txt文档并存为字符串型数组,然后就没了,
调用idl的pro,把pro放到项目文件的debug下,如果pro比较多,就新建一个IDLcode文件夹来放。
创建一个按钮调用实例:根据你的要求进行修改即可
private void button1_Click(object sender, EventArgs e)
{
//1 创建对象
COM_IDL_connectLib.COM_IDL_connectClass ocom = new COM_IDL_connectLib.COM_IDL_connectClass();
//2.对象初始化
ocom.CreateObject(0,0,0);
//3 调用idl功能
//ocom.ExecuteString("plot,sin(findgen(200)/20)");
ocom.ExecuteString(".compile '"+ Application.StartupPath + @"\IDLcode\helloworld.pro'");
ocom.ExecuteString("helloworld");
}
在 C# 中设置一个按钮点击运行某个程序可以使用事件处理程序。例如:
private void button1_Click(object sender, EventArgs e)
{
// 运行程序的代码
}
读取 txt 文档并存为字符串型数组可以使用 File.ReadAllLines 方法。例如:
string[] lines = File.ReadAllLines("file.txt");
注意,你需要在程序中引用 System.IO 命名空间才能使用此方法。
可以使用System.IO.File类来读取文件,然后使用System.Text.RegularExpressions.Regex类来将文件内容转换为字符串数组:
// 读取文件
string fileContent = System.IO.File.ReadAllText("文件路径");
// 将文件内容转换为字符串数组
string[] strArray = System.Text.RegularExpressions.Regex.Split(fileContent, "\r\n");
// 设置按钮
Button btn = new Button();
btn.Text = "运行pro";
btn.Click += new EventHandler(btn_Click);
// 按钮点击事件
void btn_Click(object sender, EventArgs e)
{
// 运行pro
// ...
}