Hide main form C# on autorun

9.3k views Asked by At

I found a realy simple method online that allows me to hide the main form in my application:

  • Create a console application

  • Set output type to Windows Forms Applications

This works perfectly when I run the application either from debugging in visual studio or manually.

However..

I have also set this application to auto start with windows (Windows 7 in this case), so I don't have to start it manually every time. When this happens there is a very very very short moment in which I can still see a full screen form blink. Is there a way I can prevent this from happening?

Edit: People seem to missing one important thing. The project is created as a Console Application, so it has no Form or Application.Run() method. It just has a single static Main method like any other Console Application.

Edit2: Just out of interest, should I rather make a normal WinForms project and try to hide that Main window using either a suggested answer or other sollution?

Thanks!

6

There are 6 answers

1
Lucas B On BEST ANSWER

what you are probably seeing is the command window appear and disappear.

I would recommend creating it either as a form and then following what Jeffery suggested or create and install it as a service that starts each time.

1
Jeffrey Hantin On

The Application.Run(Form) method makes the supplied form visible. Create the form with its Visible property initially set to false, and use the no-argument Application.Run() in your main loop.

0
Rami Alshareef On

i just tested this:

 private void Form1_Load(object sender, EventArgs e)
    {
      this.Hide();
    }

also set

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
0
Daniel Mošmondor On

Instead of

Application.Run(new MainForm())

do whatever you have to do, without any form. Your app won't be shown anywhere.

1
BHARATH_CHINNAM On

The main form cannot be hidden directly. After the form load it must do something.

Something like this:

private void Form1_Load(object sender, EventArgs e)
{
  this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
  for (int i = 0; i <= 100; i++)
  {
    progressBar1.ForeColor = Color.Blue;
    progressBar1.Value = i;
    System.Threading.Thread.Sleep(40);
    if (progressBar1.Value == 100)
    {
      Form12 f1 = new Form12();
      f1.Show();
    }
  }
  this.Opacity = 0;
  this.Visible = false;
}
0
Metallic Skeleton On

Try to hide the app from the task bar as well.

To do that please use this code.

protected override void OnLoad(EventArgs e)
   {
    Visible = false; // Hide form window.
    ShowInTaskbar = false; // Remove from taskbar.
    Opacity = 0;

    base.OnLoad(e);
   }

Thanks. Ruhul