469,362 Members | 2,417 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,362 developers. It's quick & easy.

Hide form onload

The following code does not hide the form. Any ideas why? Also, is there a
workaround?
I have VB.NET 2003.

I have a system tray icon, and want to have that be the only thing showing
when the program starts.

Matthew
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
me.hide()
End Sub
Nov 21 '05 #1
4 8966
Hi,

Me.opacity=0

Ken
-----------------------
"Matthew" <tu*************@alltel.net> wrote in message
news:e4***************@TK2MSFTNGP14.phx.gbl...
The following code does not hide the form. Any ideas why? Also, is there a
workaround?
I have VB.NET 2003.

I have a system tray icon, and want to have that be the only thing showing
when the program starts.

Matthew
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
me.hide()
End Sub

Nov 21 '05 #2
"Matthew" <tu*************@alltel.net> schrieb:
The following code does not hide the form. Any ideas why?
Also, is there a workaround?
I have VB.NET 2003.


Never call the 'Show' method of the form, and set the application's startup
object to a 'Sub Main' that contains the code for loading the form and
showing the icon.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3
Matthew,
In addition to the other comments.

It sounds like you used a Form as the startup object of your project, which
you hide, to allow having a NotifyIcon in the system tray. Correct?

Matthew MacDonald's book "Microsoft Visual Basic .NET Programmer's Cookbook"
has a topic on creating a system tray program.

Basically: Rather than using a Form as the startup object, use a Component
instead.

Create a new Component class (use Project - Add Component). Add a NotifyIcon
to the component designer. Also add a ContextMenu object for the
NotifyIcon. When you click the menu, create and show the form. Remember to
put an Exit option on the menu.

Make the Component the startup object, adding a Shared Sub Main to the
component.

Public Class Component1
Inherits System.ComponentModel.Component

' Component designer generated code omitted.

Public Shared Sub Main
Dim app as New Component1
Application.Run()
End Sub

Private Sub menuOptions_Click(...) Handles menuOptions.Click
' this would be your settings dialog.
Dim dialog as New OptionsDialog
dialog.ShowDialog()
dialog.Dispose()
End Sub

Private Sub menuExit_Click(...) Handles menuExit.Click
Me.Dispose()
Application.Exit()
End Sub

End Sub

The problem is you cannot edit the menu from the Component Designer. What I
do is use cut & paste from a Form Designer onto the Component Designer to
get the menu to the component...

The call to Me.Dispose enables the icon to be removed from the system tray
right away rather then waiting.

Hope this helps
Jay
"Matthew" <tu*************@alltel.net> wrote in message
news:e4***************@TK2MSFTNGP14.phx.gbl...
The following code does not hide the form. Any ideas why? Also, is there
a workaround?
I have VB.NET 2003.

I have a system tray icon, and want to have that be the only thing showing
when the program starts.

Matthew
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
me.hide()
End Sub

Nov 21 '05 #4
Thanks for all of your comments.
For a temporary solution, I am starting a timer that calles a me.hide()
function.

Jay, I like the looks of your idea. I'll look into it further when I have
time.

Thanks to all for your comments!

Matthew
Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Don Grover | last post: by
5 posts views Thread by Wouter | last post: by
2 posts views Thread by MOHSEN KASHANI | last post: by
4 posts views Thread by jerryyang_la1 | last post: by
chunk1978
7 posts views Thread by chunk1978 | last post: by
2 posts views Thread by mqudsi | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.