Thanks for your reply. I have two more questions.
1.) I need to call dispose before application exit
Right, as you suggest, the component object is removed immediatly when
disposed. What I would like to know is, if you do not do this first I guess
the application looks around for a while to see if it has any objects
associated with it before closing down ?
2.) In my variation of the code I simply added delegate handlers using the
constructor for the menuitem. I did not specifically add them withevents.
does this mean that this method does this implicitly, or have I dont
something wrong ?
Regards OHM
OHM,
I used cut & paste to get the menu on the component.
Remember that the menu variables need to have WithEvents on them to support
the Handles clause on the Sub.
As you found out, there are at least 3 methods of doing things in ..NET,
manually creating the menus is acceptable.
About the 3 seconds, I cannot find my sample. I want to say you need to
Dispose of the component to get the icon to disappear quicker.
If I find it later I will post the info.
Hope this helps
Jay
"One Handed Man [ OHM ]"
wrote in message I couldnt quite get your code to work, so this is what I ended up with.
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
menuOptions.MenuItems.Clear()
menuOptions.MenuItems.Add("Exit", AddressOf HandleNIExit)
'Following two items need handlers written for them, but they goto the
exit
handler for now
menuOptions.MenuItems.Add("Option1", AddressOf HandleNIExit)
menuOptions.MenuItems.Add("Option2", AddressOf HandleNIExit)
NotifyIcon1.ContextMenu = menuOptions
End Sub
AND
Sub HandleNIExit(ByVal sender As Object, ByVal e As System.EventArgs)
Application.Exit()
End Sub
message
OHM,
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
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...
Hope this helps
Jay
"One Handed Man [ OHM ]"
wrote in message If this is duplicated, I'm sorry because I cant find the
original
post
I
made today
Anyway . .
Now its my turn to ask a question
I want to develop an app which will run in the system tray. How
can