Kenyans247 Forum

Welcome, Guest: Join Kenyans247 LOGIN!

Stats: 223 Members, 11,179 topics and 65 posts Date: Tuesday 31 March 2020 at 04:03 PM
TrendingRecentNewestClassifiedDirectoryLivescoresLive Kenyan TVLive Kenyan Radio

Get Command Line Arguments in a Windows Forms Application

Kenyans247 / Science/Technology / Computers / Get Command Line Arguments in a Windows Forms Application (14 View's)

Display A List Of Started Services From The Command Line (windows) Kill Processes From The Windows Command Line Kill A Process By Process Name From Ubuntu Command Line Search For Install Packages From The Ubuntu Command Line
(Go Down) (» Reply topic)
Get Command Line Arguments in a Windows Forms Application by Kenyans247(m): Sun 22, March, 2020 10:22am
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:

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.

(» Reply topic) (» Go Up)

Recommended for you

» Get Command Line Arguments In A Windows Forms Application » Kill Processes From The Windows Command Line » Kill A Process By Process Name From Ubuntu Command Line » Display A List Of Started Services From The Command Line (windows)
Viewing this topic:
1 guest(s) viewing this topic

Sections: How To, International Forum, Homepage, Africa, Autos, Education, Innovation, Building/Architecture, Art, Graphics & Video, Webmasters, K247 TV, Literature, Theatre/Comedy, Events, Poetry, Tanzania Forum, Ugandan Forum, Somalia Forum, Rwanda Forum, Burundi Forum,

Kenyans247 - Copyright © 2019 - 2020 Sande Kennedy. All rights reserved. See How To Advertise.
Disclaimer: Every Kenyans247 member is solely responsible for anything that he/she posts or uploads on Kenyans247.