Hiding initial form in VB

  • Thread starter Thread starter Michael Rich
  • Start date Start date
M

Michael Rich

I am writing a program that primaryly runs in the system tray. When the
program starts, I would like to hide the main form and only show the tray
icon.

in the Form Load event I set Me.Visible = False, but this does not hide the
form. In the Form Activate event, if I set the same thing, the form is
never displayed.

There has got to be an easy way to do that I am overlooking.

Thanks;
Michael
 
Michael Rich said:
I am writing a program that primaryly runs in the system tray. When the
program starts, I would like to hide the main form and only show the tray
icon.

in the Form Load event I set Me.Visible = False, but this does not hide the
form. In the Form Activate event, if I set the same thing, the form is
never displayed.

There has got to be an easy way to do that I am overlooking.

Why don't you create a class for your system tray icon and create an
instance of this on startup instead of your form? You'll need to set your
startup object to Sub Main and initialise your class from there.

HTH.
 
I asked the same question a few months back.
The solution is to set your apps startup object as Sub Main()

Sub Main()
Dim frm As Form = New Form1()
Application.Run()
End Sub

After Main() has executed, your Form1 with the NotifyIcon component exists
but is not yet visible.
 
Michael Rich said:
I am writing a program that primaryly runs in the system tray. When
the program starts, I would like to hide the main form and only show
the tray icon.

in the Form Load event I set Me.Visible = False, but this does not
hide the form. In the Form Activate event, if I set the same thing,
the form is never displayed.

There has got to be an easy way to do that I am overlooking.

Don't use a startup form. Use a sub main. There, you can either only show
the tray icon, or create the try icon and create the form without showing
it.
 
Hi Armin,
I become curious, there are so many answers after I gave early this morning
the advise to use
Me.Windowstate=FormWindowState.minimized
That I think, what is wrong with that (no critique feel free to add when I
post something can only add my knowledge)
Or has this to do with some time lags between newsservers?
Cor
 
Cor said:
Hi Armin,
I become curious, there are so many answers after I gave early this
morning the advise to use
Me.Windowstate=FormWindowState.minimized
That I think, what is wrong with that (no critique feel free to add
when I post something can only add my knowledge)
Or has this to do with some time lags between newsservers?
Cor

As often I don't understand you. :-/ Do you wonder why there are posts after
yours or why the suggestions are different?
 
Hello,

Cor said:
I become curious, there are so many answers after I gave
early this morning the advise to use
Me.Windowstate=FormWindowState.minimized
That I think, what is wrong with that (no critique feel free to add when I
post something can only add my knowledge)
Or has this to do with some time lags between newsservers?

Ng communication is asynchronous. Some people download the new messages
only 1-3 times per day, write the answers and upload them when downloading
the new messages the next time. That's why some people may not see your
reply when writing their answer.

Regards,
Herfried K. Wagner
 
No Armin,
I was wondering if there was a error in my message.
Because I did n't see it repeated and I am not that clever.

But Herfried has given the answer
Cor
 
Back
Top