C#.NET winform - launch by command line or normal

I am trying to run a C#.net windows application that has the ability to run from command line parameters and/or just launch normally.  Basically I have a Sub named Main that obtains the command line arguments but how do I get it to just launch Form1 if there are none?

====================================================================
Here is what my Main looks like:
====================================================================
        static void Main(string[] args)
        {
            // Set up a string variable to concatenate all of the arguments in.
            string strArgs = "";

            // Loop through all of the arguments, adding them to the string variable.
            foreach (string arg in args)
            {
                strArgs = strArgs + (arg) + " ";
            }

            // Display the command line arguments.
            MessageBox.Show(strArgs.ToString());

            // Proceed to launching the application as usual.
            ???
        }
scott_46077Asked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
To continue the app with a Form, use Application.Run():

    Application.Run(new Form1());

You just need to add the check for command line args...
0
 
jef06Commented:

Application.Run(yourform); where your form is your main form
0
 
scott_46077Author Commented:
Thanks everyone.  I am primarily an ASP.NET developer, starting to do some winform development.  Worked like a charm.
0
 
scott_46077Author Commented:
Here is the code that I ended up using:
====================================================
        /// <summary>
        /// The start-up item in the project.  It checks for command line arguments.
        /// If found it processes them, if not it launches form1.
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            // Obtain the number of arguments found in the command line.
            int intCount = args.Length;

            // If no arguments are found, display Form1.
            if (intCount == 0)
            {
                // Proceed to launching the application as usual.
                Application.Run(new Form1());
            }

            // Set up a string variable to concatenate all of the arguments in.
            string strArgs = "";

            // Loop through all of the arguments, adding them to the string variable.
            foreach (string arg in args)
            {
                strArgs = strArgs + (arg) + " ";
            }

            // Display the command line arguments.
            MessageBox.Show(strArgs.ToString());
        }
0
 
Ignis2Commented:
Looks good - thanks, that's what I was looking for! Will try it out and let you know!!

0
All Courses

From novice to tech pro — start learning today.