Hide main C # form on startup

I found a very easy way 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 great when I run the application either from debugging in visual studio, or manually.

However..

I also installed this application to start automatically from Windows (in this case, Windows 7), so I do not need to run it manually each time. When this happens, a very very short moment occurs when I still see the blinking in full screen. Is there any way to prevent this?

Edit: people don't seem to know anything important. A project is created as a console application, so it has a form or .Run () application method . It just has one static Main method, like any other console application.

Edit2: Just out of interest, should I make a normal WinForms project and try to hide this main window using either the proposed answer or another solution?

Thank!

+3
source share
6 answers

what you probably see is the command window appears and disappears.

I would recommend creating it either as a form, and then after what Geoffrey has proposed or created and installed as a service that runs every time.

0
source
+3

I just tested this:

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

also installed

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
+2
source

Try also to hide the application on the taskbar.

Use this code for this.

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

    base.OnLoad(e);
   }

Thank. Ruhul

+1
source

Instead

Application.Run(new MainForm())

do whatever you need without any form. Your application will not be displayed anywhere.

0
source

The main form cannot be hidden directly. After loading the form, he must do something.

Something like that:

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
source

Source: https://habr.com/ru/post/1792647/


All Articles