Get Command Line Arguments in a Windows Forms Application
A useful technique for your applications is allowing them to parse
command line arguments. This can give a lot of extra functionality to
your application, for instance to pass the name of a file to open on the
command line.
Most of the examples you’ll find online will show you something like this:
Thankfully, this is completely unnecessary, because you can simply do this:
Most of the examples you’ll find online will show you something like this:
static void Main(string[] args) { foreach(string arg in args) { Console.WriteLine(arg); } Console.ReadLine(); }That’s all fine and good, except that won’t work for our Windows Forms application without changing the type of the project to console, etc.
Thankfully, this is completely unnecessary, because you can simply do this:
string[] args = Environment.GetCommandLineArgs(); foreach(string arg in args){ // do stuff }And you can use this anywhere in your application, you aren’t just restricted to using it in the main() method like in a console application.
Get Command Line Arguments in a Windows Forms Application
Reviewed by Pakainfo
on
August 08, 2018
Rating:
No comments: