Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide main form C# on autorun

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!

like image 758
SaphuA Avatar asked Nov 01 '25 16:11

SaphuA


2 Answers

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.

like image 133
Jeffrey Hantin Avatar answered Nov 04 '25 07:11

Jeffrey Hantin


i just tested this:

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

also set

this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
like image 38
Rami Alshareef Avatar answered Nov 04 '25 07:11

Rami Alshareef



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!