4

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!

SaphuA
  • 3,092
  • 3
  • 39
  • 58

6 Answers6

3

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.

Jeffrey Hantin
  • 35,734
  • 7
  • 75
  • 94
  • @SaphuA You don't have a user32 message loop on your main thread at all? I wonder if that may be a factor. Try calling `Application.DoEvents()` at the top of your `Main`; does that have any effect on its behavior? – Jeffrey Hantin Feb 16 '11 at 22:08
3

i just tested this:

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

also set

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
Rami Alshareef
  • 7,015
  • 12
  • 47
  • 75
2

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;
}
Scott
  • 21,211
  • 8
  • 65
  • 72
  • 1
    Could you rephrase your question? It's hard to understand what you mean and what you want to achieve. – Bakuriu Oct 09 '12 at 14:15
2

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

0

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.

Lucas B
  • 11,793
  • 5
  • 37
  • 50
  • Thanks for your reply. You'd think the command window would pop up, but I'm fairly sure it's a WinForms window, as it's white. Weird huh? – SaphuA Feb 17 '11 at 06:22
0

Instead of

Application.Run(new MainForm())

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

Daniel Mošmondor
  • 19,718
  • 12
  • 58
  • 99