向WinForm程序传递命令行参数以及让程序后台运行的

 1  [STAThread]

 2         static void Main(string[] args)

 3         {

 4             Application.EnableVisualStyles();

 5             Application.SetCompatibleTextRenderingDefault(false);

 6             if (args.Length == 0)

 7                 Application.Run(new Form1());

 8             else

 9                 Application.Run(new Form1(args));

10         }
public partial class Form1 : Form

    {

        string[] args = null;

        public Form1()

        {

            InitializeComponent();

        }

        public Form1(string[] args)

        {

            InitializeComponent();

            this.args = args;

        }



        private void Form1_Load(object sender, EventArgs e)

        {

            if (args != null)

            {

                for (int i = 0; i < args.Length; i++)

                    MessageBox.Show(args[i]);

            }          

            MessageBox.Show("output done!");

            System.Environment.Exit(0); // exit program

        }

    }

 

你可能感兴趣的:(WinForm)