I have an application that is a part of a solution of projects. In this project I would like for it to start up form to be invisible, but still have a notification icon in t
Here is another way that I've found to do this.
Set the form properties with
ShowInTaskbar = False
Then in the form's constructor add
WindowState = FormWindowState.Minimized
This is very easy to implement and works with no flicker. In my case I also use a NotifyIcon to access the program from the notification tray and just set
WindowState = FormWindowState.Normal
Show()
BringToFront()
In the Notify_MouseClick event handler.
To hide the form again after displaying it, just minimizing again doesn't quite do the job. In my case I use the Form_Closing event and just hide the form.
Hide()
Paste this in your form code:
Protected Overrides Sub SetVisibleCore(ByVal value As Boolean)
If Not Me.IsHandleCreated Then
Me.CreateHandle()
value = False
End If
MyBase.SetVisibleCore(value)
End Sub
The way that works is that the very first request to show the form, done by the Application class, this code overrides the Visible property back to False. The form will behave as normal after this, you can call Show() to make it visible and Close() to close it, even when it was never visible. Note that the Load event doesn't fire until you show it so be sure to move any code in your event handler for it, if any, to the constructor or this override.
Try this:
Sub New()
MyBase.SetVisibleCore(False)
End Sub
Put this in the form's Shown event
Me.Visible = False
The easiest way is to set the opacity of the form to 0%. When you want it to appear, set it back to 100%
Just to throw out a completely different approach, have you considered not using the overload of Application.Run()
that takes (and automatically shows) a Form
? If you use the one that passes in an ApplicationContext
(or more tyoically, your own subclass of ApplicationContext
) then you can choose what your behavior is. See here for more details:
http://msdn.microsoft.com/en-us/library/ms157901