I have an application with one form in it, and on the Load method I need to hide the form.
The form will display itself when it has a need to (think along the lines of a outlook 2003 style popup), but I can' figure out how to hide the form on load without something messy.
Any suggestions?
I'm coming at this from C#, but should be very similar in vb.net.
In your main program file, in the Main method, you will have something like:
This creates a new main form and limits the lifetime of the application to the lifetime of the main form.
However, if you remove the parameter to Application.Run(), then the application will be started with no form shown and you will be free to show and hide forms as much as you like.
Rather than hiding the form in the Load method, initialize the form before calling Application.Run(). I'm assuming the form will have a NotifyIcon on it to display an icon in the task bar - this can be displayed even if the form itself is not yet visible. Calling
Form.Show()
orForm.Hide()
from handlers of NotifyIcon events will show and hide the form respectively.I use this:
Obviously you have to change the if condition with yours.
This example supports total invisibility as well as only NotifyIcon in the System tray and no clicks and much more.
More here: http://code.msdn.microsoft.com/TheNotifyIconExample
Override OnVisibleChanged in Form
You can add trigger if you may need to show it at some point
At form construction time (Designer, program Main, or Form constructor, depending on your goals),
When you need to show the form, presumably on event from your NotifyIcon, reverse as necessary,
Successive show/hide events can more simply use the Form's Visible property or Show/Hide methods.
This works perfectly for me:
When I launch the project, everything was hidden including in the taskbar unless I need to show it..