C #, winfrom add command line parameters to the program

Source: Internet
Author: User

The parameter given in the command line is the command line parameter.

Command line parameters are separated by spaces.

However, if the command line parameter itself contains spaces, the parameter must be enclosed in a pair of double quotation marks.

Eg: d: \ loading.exe-t = 5000

// Program. cs

 
Static class Program {////// Main entry point of the application. ///Static void Main (string [] args) {Application. EnableVisualStyles (); Application. SetCompatibleTextRenderingDefault (false); Application. Run (new WelCome (args ));}}

 

 

// Obtain the program

 

////// Configure ///Public WelCome (string [] args) {InitializeComponent (); foreach (string arg in args) {// The passed parameter-t is the time when the form is displayed if (arg. contains ("-t =") {string strTime = arg. substring (arg. indexOf ('=') + 1); int time = 200; if (int. tryParse (strTime, out time) {this. kltimer. interval = time ;}}}}

Summary:

 

Use the main program entry that can pass a string array. The characters in the array are the command line parameters.


Windows + r enter exepath args1 args2 to run

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.