472,145 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

System Tray Applications

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 I do
this?
Regards OHM
Nov 20 '05 #1
10 3573
"One Handed Man [ OHM ]"
<te***************************@BTOpenworld.com> schrieb
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 I
do this?


There is not much space in the system tray, so your app might get hurt. ;-))
Use the NotifyIcon component (System.Windows.Forms.NotifyIcon)
--
Armin

Nov 20 '05 #2
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 ]" <te***************************@BTOpenworld.com>
wrote in message news:e%****************@TK2MSFTNGP12.phx.gbl...
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 I do
this?
Regards OHM

Nov 20 '05 #3

"Armin Zingler" <az*******@freenet.de> wrote in message
news:OT**************@TK2MSFTNGP12.phx.gbl...
"One Handed Man [ OHM ]"
<te***************************@BTOpenworld.com> schrieb
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 I
do this?
There is not much space in the system tray, so your app might get hurt.

;-))

*sigh*... I know you didn't just say that....
Use the NotifyIcon component (System.Windows.Forms.NotifyIcon)
--
Armin

Nov 20 '05 #4
Excellent - Thank You

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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 ]" <te***************************@BTOpenworld.com>
wrote in message news:e%****************@TK2MSFTNGP12.phx.gbl...
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 I do
this?
Regards OHM


Nov 20 '05 #5
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

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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 ]" <te***************************@BTOpenworld.com>
wrote in message news:e%****************@TK2MSFTNGP12.phx.gbl...
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 I do
this?
Regards OHM


Nov 20 '05 #6

The icon takes about 30 seconds to disapear from the tray eafter exit. Is
this expected ?

"One Handed Man [ OHM ]" <te***************************@BTOpenworld.com>
wrote in message news:uN**************@tk2msftngp13.phx.gbl...
Excellent - Thank You

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl...
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 ]" <te***************************@BTOpenworld.com>
wrote in message news:e%****************@TK2MSFTNGP12.phx.gbl...
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 I do this?
Regards OHM



Nov 20 '05 #7
OHM,
I found my sample. You need to call the Dispose method of the Component
before you call Application.Exit.

In VS.NET this causes the icon to disappear 'immediately'.

FWI: you should use the NotifyIcon.MouseDown & NotifyIcon.MouseUp events if
you want to track which mouse button was pressed instead of the
NotifyIcon.Click event. I had 'trouble' with this when I first worked with
my sample. Took me 'for ever' to figure out what to do ;-)

Hope this helps
Jay

"One Handed Man [ OHM ]" <te***************************@BTOpenworld.com>
wrote in message news:eC**************@TK2MSFTNGP12.phx.gbl...

The icon takes about 30 seconds to disapear from the tray eafter exit. Is
this expected ?

"One Handed Man [ OHM ]" <te***************************@BTOpenworld.com>
wrote in message news:uN**************@tk2msftngp13.phx.gbl...
Excellent - Thank You

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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 ]"
<te***************************@BTOpenworld.com> wrote in message news:e%****************@TK2MSFTNGP12.phx.gbl...
> 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
I
do > this?
>
>
> Regards OHM
>
>



Nov 20 '05 #8
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

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:uG**************@TK2MSFTNGP11.phx.gbl...
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 ]" <te***************************@BTOpenworld.com>
wrote in message news:eF**************@TK2MSFTNGP09.phx.gbl...
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

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in

message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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 ]"
<te***************************@BTOpenworld.com> wrote in message news:e%****************@TK2MSFTNGP12.phx.gbl...
> 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
I
do > this?
>
>
> Regards OHM
>
>



Nov 20 '05 #9
OHM,
1.) I need to call dispose before application exit Actually the program exits, about 3 seconds later Windows notices that the
program for the icon is not running any more and removes the icon. You can
see the same effect if you start the program in VS.NET. Then use the VS.NET
'Debug - Stop Debugging' command. Also if you move the mouse over the icon
the icon will disappear in this case.
2.) In my variation of the code I simply added delegate handlers using the
The MenuItem constructor that accepts the delegate is calling AddHandler
inside. So yes the constructor is doing it implicitly. It is valid and is
easier when creating menus without the aid of the designer.

Hope this helps
Jay
"One Handed Man [ OHM ]" <te***************************@BTOpenworld.com>
wrote in message news:Oc**************@tk2msftngp13.phx.gbl... 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

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:uG**************@TK2MSFTNGP11.phx.gbl...
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 ]" <te***************************@BTOpenworld.com>
wrote in message news:eF**************@TK2MSFTNGP09.phx.gbl...
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

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in

message
news:%2****************@TK2MSFTNGP11.phx.gbl...
> 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 ]"

<te***************************@BTOpenworld.com> > wrote in message news:e%****************@TK2MSFTNGP12.phx.gbl...
> > 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 I
do
> > this?
> >
> >
> > Regards OHM
> >
> >
>
>



Nov 20 '05 #10
Many thanks for your help, I'm off and running now.
Regards - OHM

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:eO**************@TK2MSFTNGP09.phx.gbl...
OHM,
1.) I need to call dispose before application exit Actually the program exits, about 3 seconds later Windows notices that the
program for the icon is not running any more and removes the icon. You can
see the same effect if you start the program in VS.NET. Then use the

VS.NET 'Debug - Stop Debugging' command. Also if you move the mouse over the icon
the icon will disappear in this case.
2.) In my variation of the code I simply added delegate handlers using the

The MenuItem constructor that accepts the delegate is calling AddHandler
inside. So yes the constructor is doing it implicitly. It is valid and is
easier when creating menus without the aid of the designer.

Hope this helps
Jay
"One Handed Man [ OHM ]" <te***************************@BTOpenworld.com>
wrote in message news:Oc**************@tk2msftngp13.phx.gbl...
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

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in

message
news:uG**************@TK2MSFTNGP11.phx.gbl...
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 ]" <te***************************@BTOpenworld.com> wrote in message news:eF**************@TK2MSFTNGP09.phx.gbl...
> 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
>
>
>
> "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in
message
> news:%2****************@TK2MSFTNGP11.phx.gbl...
> > 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 ]"

<te***************************@BTOpenworld.com>
> > wrote in message news:e%****************@TK2MSFTNGP12.phx.gbl...
> > > 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
I
do
> > > this?
> > >
> > >
> > > Regards OHM
> > >
> > >
> >
> >
>
>



Nov 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by joe | last post: by
4 posts views Thread by Robert Samuel White | last post: by
10 posts views Thread by Crouchie1998 | last post: by
2 posts views Thread by ericlangland | last post: by
3 posts views Thread by Usman Jamil | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.