How to hide a form on initialization

aewarnick

Well-known member
Joined
Jan 29, 2003
Messages
1,031
I cannot use Hide() or the visible property in the constructor or Load() to hide my form when it is initializing.

I cannot leave out the constructor code because this program runs in the background. The form needs to be initialized but I dont want the user to see it until they click the notify icon.
 
When the user opens the exe file I dont want it to show the form but a notify icon will be in the taskbar for the user to Show() the form with.
 
Is your problem/question related to running your application on your own computer or on being able to run it on other machines... While the other machines do Not have Visual Studio .Net installed?
 
Ohhhhh hhhh h!
It will be distributed to anyone and I think it will be free too. They will most likely not have VS.
 
I guess Robby was saying that it would be better if you posted this question in the Windows Forms area, since it has nothing to do with deployment.
 
Maybe divil would be so kind as to move the thread for me...I dont want to post this twice.
 
Last edited by a moderator:
Well anyway the answer to hiding the form on startup is.

Set the windows state to minimize on startup
Hide it from the task bar

then when you show the form
restore the windows state to normal then
show

Thats the easiest way I have found to do it.
 
Thanks TreasonX. I already tried that. The problem is that the form is still accessable to the user that way. All they have to do is use Alt + Tab to veiw any open form in windows.

There has got to be a better way.
 
Thanks Tx, I will probably make my own class with methods called show and hide to handle those things form my forms.
 
i tired getting that to work same problem as u
so i used a OnPaint event and hide the form

my app paints the panel

so i just used a boolean
and set it to true once it had hid the form on startup once and then on exit set it back to false so that it will work the next time
 
Hey guyyyyysss!! I found the answer to this question and it is muuuuuch better than minimising the form and hiding the taskbar box. I was looking and reading some info here:
http://www.syncfusion.com/FAQ/WinForms/
and found out about this great resource in VS help:
search for this: Setting a Form to Be Invisible at Its Inception

Now, the problem is that I need to know if windows is closing the form or if the user is because windows will not restart when the form is running unless I use Application.Exit().

How can I tell how the form is being closed?
 
Theres a reason why that FAQ is permanently posted at the top of this forum ;)

You can listen for the SystemEvents.SessionEnding event to tell when the user is trying to log off or shutdown the system.
 
Back
Top