Thursday, 23 June 2011

how to pass command line arguments in the main form of an application

1. open the "program.cs" file form solution explorer of vs

2. in the follow code... add the red marked text
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain(args));  //Your Form might not named FormMain
        }

3.  Open your Main Form -> right click -> view code, to see the actual code

4. Modify the follow code, add again the red marked text
        public FormMain(string[] args)           //Your Form might not named FormMain

At this point in the FormMain contructor the args string array contains the command line arguments.
How to add arguments now in VS?

5. From solution explorer of vs -> double click the "properties" node -> click on "debug" tab -> type your arguments in "command line arguments" box

No comments:

Post a Comment