In addition, since all WinForms applications start as the result of a static Main being run, you can always grab the parms right off of the args collection. Something like:
[STAThread()] private static void Main(string[] args) { MySpecialForm frm = new MySpecialForm(); foreach(string arg in args) { switch(arg) { case "-switch"; frm.Switch = true; break; default: frm.AddFileName(arg); break; } }
Application.Run(frm); }
This gives you the ability to make your from class what I would call a runnable dialog window. You could literally re-use this form in any application, because it now has properties and methods you can call to set it up just like any other workhorse class. All of the init work in this case happens in the Main method, but if you were using this instead as a tool, you might imagine launching an Open File dialog and custom UI to set the switches then using the results to call this same form.
I highly recommend against using the Environment.CommandLine in any Form overloads since they are then dependent on being run in a very specific way and lose a LOT of their reusability. |