I use the following code to pass the first argument (the one that contains the file name) to my gui application:
static class Program {
[STAThread]
static void Main(string[] args) {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(args.Length == 0 ? new Form1(string.Empty) : new Form1(args[0]));
}
}
I check if there is an argument. If not, and the user runs your program without it, you can get an exception in any code that tries to use it.
This is a snippet from my Form1 that processes the input file:
public Form1(string path) {
InitializeComponent();
if (path != string.Empty && Path.GetExtension(path).ToLower() != ".bgl") {
} else {
MessageBox.Show("Dropped File is not Bgl File","File Type Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
path = string.Empty;
}
}
, - -.bgl - , , . . ( ),
, . .