Reputation: 2555
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 the tray visible for this form.
I know that adding me.hide
into the form_load
doesn't work. I tried adding a module that instantiates the startup form and I set it as the startup object. Although that didn't work either. I am running out of ideas to have this form invisible. Could anyone help out? I am using VB.NET.
Upvotes: 15
Views: 35254
Reputation: 126
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()
Upvotes: 3
Reputation: 51
Use Me.Opacity = 0
to hide the form on load event.
Then use the following code in the form.Shown event
Me.Hide()
Me.Opacity = 100
Upvotes: 2
Reputation: 61
The easiest way is to set the opacity of the form to 0%. When you want it to appear, set it back to 100%
Upvotes: 6
Reputation: 10855
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
Upvotes: 1
Reputation: 942247
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.
Upvotes: 28