Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Another NotifyIcon Question

778 views
Skip to first unread message

Kevin Buchan

unread,
Aug 15, 2003, 11:57:42 AM8/15/03
to
I searched throughout history in this newsgroup and could not find my
question asked before... this probably means that it's too simple a
question.

Here's the deal... I want to have a program that shows only a system
tray icon when it starts and let that icon show a menu and popup a
form based on various interactions.

In VB6, when I wanted to do this, I'd use a class I wrote to manage
the system tray stuff and I'd just call "Me.Hide" in the Form_Load
event.

With .Net, I can get everything to work except for the hiding of the
initial form. Setting the 'Visible' property or calling the 'Hide'
method don't seem to affect the visibility of the Form from the Load
event. The closest I've come is hiding the form from a timer, but
this leaves the form visible for too long and looks retarded.

This has got to be a super easy thing to do, but I seem to be unable
to divine the solution.


-Kevin Buchan
kevin....@REMOVETHISTOEMAILtroutmansanders.com

Jay B. Harlow [MVP - Outlook]

unread,
Aug 15, 2003, 12:30:17 PM8/15/03
to
Kevin,
Do not use 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
Dim dialog as New OptionsDialog
dialog.ShowDialog()
dialog.Dispose()
End Sub

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

End Sub

The problem is you cannot edit the menu from the Component Designer. You
can use cut & paste from a form to get the menu to the component...

Matthew MacDonald's book "Microsoft Visual Basic.NET Programmer's Cookbook"
from MS press has a complete writup on how to do this.

Hope this helps
Jay

"Kevin Buchan" <kevin....@troutmanNOSPAMsanders.com> wrote in message
news:s30qjvsk1m27mu7q9...@4ax.com...

Kevin Buchan

unread,
Aug 15, 2003, 1:01:59 PM8/15/03
to
How creative! Thanks so much.


-Kevin Buchan
kevin....@REMOVETHISTOEMAILtroutmansanders.com

0 new messages