views:

76

answers:

1

I am trying to make my application load hidden when windows loads. I have created a shortcut with a parameter and I am trying to hide the form if the parameter equals to "WINDOWS". But the Form is ALWAYS shown regardless I hide the form or set the visibility to false. How do i get about doing this?

[MTAThread]
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Debug.WriteLine("Arguments were passed");
                foreach (string item in args)
                {
                    MessageBox.Show(item);
                }


                Application.Run(new frmMain("WINDOWS"));
            }    

        }

and in the constructor of frmMain

public frmMain(string Argument)
        {
            InitializeComponent();

            if (Argument != null && Argument != "")
            {                
                if (Argument == "WINDOWS")
                {
                    this.Visible = false;
                    //Hide();
                }  
           }

But the frmMain window is ALWAYS shown. How do make it load hidden?

Thanx a lot in advance :)

+1  A: 

The definition for the Application.Run(Form) method is:

"Begins running a standard application message loop on the current thread, and makes the specified form visible."

You could create the form, then sleep, or block, until you want the Form to be visible, and then call Application.Run() on the Form you created when it's time to show it.

If the application needs to perform tasks even before the Form is displayed, you could place that code outside the Form's logic (or even not use a Form at all).

deltreme