I wrote an application that by design, when minimized, goes to the tray, and will only show up as a normal form when you doubleclick the icon in the tray.
To do this, I added a NotifyIcon, and added these functions:
This works fine, but I want the program to start minimized to the tray. So I added this line to the very end of Form1_Load:
Private Sub Form1_Resize(sender As System.Object, e As System.EventArgs) Handles MyBase.Resize
If Me.WindowState = FormWindowState.Minimized Then
NotifyIcon1.Visible = True
ShowInTaskbar = False
Private Sub NotifyIcon1_DoubleClick(sender As System.Object, e As System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.WindowState = FormWindowState.Normal
NotifyIcon1.Visible = False
ShowInTaskbar = True
When I run my program in debug mode within Visual Studio, this works fine.
Me.WindowState = FormWindowState.Minimized
When I run the exe directly, the form does not hide properly. It "minimizes" by resizing to a very small size, and looks like this, fixed in the lower-left corner of my screen:
If I click the restore button, it restores and the restore button turns into a minimize button. If I click the minimize button, it minimizes to the tray correctly. But I want it to start that way. What is going wrong and how do I fix it?