how to make form invisible on startup?

I have an application that minimises to system tray and runs on windows startup. I would like the application to start with the main form invisible when loaded. Everything I've tried so far has failed. Any ideas

Answer this question

how to make form invisible on startup?

  • June Shi

    I tried setting this.Visible = false but that does not seem to work. It still shows. I think after the form load event is done show() is called, which overrides the visibility setting (or something like that).

    Setting size to 0,0 may work but that doesn't seem like a good solution.

    I also tried putting code in the VisibleChanged event. If I put this.Visible = false in there then the  form will not show...ever! Since it will always get set to invisible.

    I tried adding a boolean toggle in the VisibleChanged event such that on the first call it gets set to invisible, then gets ignored. That didn't work either. Seems VisibleChanged gets called around 3 times at startup.

  • Kedar

    Have you tried setting it after the initialisation call You've obviously calling it too early

    Attacking the VisibleChanged event could work, if you checked your own variable in there to see if you were allowing the form to be shown.  i.e. create a bool and set it to false initially, and true when you want to call Visible= true and for it to work.

    Ah - just read your next comment.  Yes, you'd need to control the boolean toggle explicitly.


  • NitinVaghela

    Yes, that seems to work quite well now. Here's my solution for future reference:

    I have a boolean stayHidden which gets initialized when the form is created depending on wheather or not the program was started with a command line argument or not.

    Then in the VisibleChanged event of the formI have:

    if(stayHidden) this.Visible = false;

    This sets the form invisible when it loads.

    I made the application so double-clicking on the sys-tray icon shows the form. So in the double click event of the notification icon I just set stayHidden = false which basically disables the VisibleChanged event and the form can now be show/hidden as normal.

  • Ranjay

    What have you tried Two things spring to mind, first this.Visible = false, secondly, you could set the size to be 0,0, or the position to be outside the visible desktop.  The first one is obviously the non-hack.


  • how to make form invisible on startup?