使用字符串作为输入参数初始化表单



我的c#程序是一个文本编辑器,需要文件名作为输入参数。换句话说,我想从指定要打开哪个文件的 BAT 文件启动 c# EXE。例如:"调用 C:\Temp\MyDotNetApp File1",其中"File1"是 C# 中程序的输入参数。

这在 C# 中可能吗?我在互联网上找不到任何教程。

我的代码:

namespace CSVEditor{
     public partial class Form1 : Form { 
     public static string TAG = "";
     public static string FileLinnk = "";
}
public Form1()
    {
        InitializeComponent();          
    }
private void Form1_Load(object sender, EventArgs e)
    {
        //Input file to read
        File = "File1";// <----- This needs to be the input parameeter from BAT file.
        //
        FileLink = @"c:temp" + File + ".csv";
        ReadCSV(FileLink);
    }

干杯。

只需使用 Environment.GetCommandLineArgs ;

string[] args = Environment.GetCommandLineArgs();

最新更新