473,544 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3654
"One Handed Man [ OHM ]"
<te************ *************** @BTOpenworld.co m> 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.NotifyIc on)
--
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.Componen tModel.Componen t

' Component designer generated code omitted.

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

Private Sub menuOptions_Cli ck(...) Handles menuOptions.Cli ck
Dim dialog as New OptionsDialog
dialog.ShowDial og()
dialog.Dispose( )
End Sub

Private Sub menuExit_Click( ...) Handles menuExit.Click
Application.Exi t()
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.co m>
wrote in message news:e%******** ********@TK2MSF TNGP12.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*******@free net.de> wrote in message
news:OT******** ******@TK2MSFTN GP12.phx.gbl...
"One Handed Man [ OHM ]"
<te************ *************** @BTOpenworld.co m> 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.NotifyIc on)
--
Armin

Nov 20 '05 #4
Excellent - Thank You

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.Componen tModel.Componen t

' Component designer generated code omitted.

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

Private Sub menuOptions_Cli ck(...) Handles menuOptions.Cli ck
Dim dialog as New OptionsDialog
dialog.ShowDial og()
dialog.Dispose( )
End Sub

Private Sub menuExit_Click( ...) Handles menuExit.Click
Application.Exi t()
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.co m>
wrote in message news:e%******** ********@TK2MSF TNGP12.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.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

menuOptions.Men uItems.Clear()

menuOptions.Men uItems.Add("Exi t", AddressOf HandleNIExit)

'Following two items need handlers written for them, but they goto the exit
handler for now

menuOptions.Men uItems.Add("Opt ion1", AddressOf HandleNIExit)

menuOptions.Men uItems.Add("Opt ion2", AddressOf HandleNIExit)

NotifyIcon1.Con textMenu = menuOptions

End Sub

AND

Sub HandleNIExit(By Val sender As Object, ByVal e As System.EventArg s)

Application.Exi t()

End Sub

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.Componen tModel.Componen t

' Component designer generated code omitted.

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

Private Sub menuOptions_Cli ck(...) Handles menuOptions.Cli ck
Dim dialog as New OptionsDialog
dialog.ShowDial og()
dialog.Dispose( )
End Sub

Private Sub menuExit_Click( ...) Handles menuExit.Click
Application.Exi t()
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.co m>
wrote in message news:e%******** ********@TK2MSF TNGP12.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.co m>
wrote in message news:uN******** ******@tk2msftn gp13.phx.gbl...
Excellent - Thank You

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message news:%2******** ********@TK2MSF TNGP11.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.Componen tModel.Componen t

' Component designer generated code omitted.

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

Private Sub menuOptions_Cli ck(...) Handles menuOptions.Cli ck
Dim dialog as New OptionsDialog
dialog.ShowDial og()
dialog.Dispose( )
End Sub

Private Sub menuExit_Click( ...) Handles menuExit.Click
Application.Exi t()
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.co m>
wrote in message news:e%******** ********@TK2MSF TNGP12.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.Exi t.

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

FWI: you should use the NotifyIcon.Mous eDown & NotifyIcon.Mous eUp events if
you want to track which mouse button was pressed instead of the
NotifyIcon.Clic k 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.co m>
wrote in message news:eC******** ******@TK2MSFTN GP12.phx.gbl...

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

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

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.Componen tModel.Componen t

' Component designer generated code omitted.

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

Private Sub menuOptions_Cli ck(...) Handles menuOptions.Cli ck
Dim dialog as New OptionsDialog
dialog.ShowDial og()
dialog.Dispose( )
End Sub

Private Sub menuExit_Click( ...) Handles menuExit.Click
Application.Exi t()
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.co m> wrote in message news:e%******** ********@TK2MSF TNGP12.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********@ema il.msn.com> wrote in message
news:uG******** ******@TK2MSFTN GP11.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.co m>
wrote in message news:eF******** ******@TK2MSFTN GP09.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.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

menuOptions.Men uItems.Clear()

menuOptions.Men uItems.Add("Exi t", AddressOf HandleNIExit)

'Following two items need handlers written for them, but they goto the exit
handler for now

menuOptions.Men uItems.Add("Opt ion1", AddressOf HandleNIExit)

menuOptions.Men uItems.Add("Opt ion2", AddressOf HandleNIExit)

NotifyIcon1.Con textMenu = menuOptions

End Sub

AND

Sub HandleNIExit(By Val sender As Object, ByVal e As System.EventArg s)

Application.Exi t()

End Sub

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

message
news:%2******** ********@TK2MSF TNGP11.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.Componen tModel.Componen t

' Component designer generated code omitted.

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

Private Sub menuOptions_Cli ck(...) Handles menuOptions.Cli ck
Dim dialog as New OptionsDialog
dialog.ShowDial og()
dialog.Dispose( )
End Sub

Private Sub menuExit_Click( ...) Handles menuExit.Click
Application.Exi t()
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.co m> wrote in message news:e%******** ********@TK2MSF TNGP12.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.co m>
wrote in message news:Oc******** ******@tk2msftn gp13.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********@ema il.msn.com> wrote in message news:uG******** ******@TK2MSFTN GP11.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.co m>
wrote in message news:eF******** ******@TK2MSFTN GP09.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.

InitializeCompo nent()

'Add any initialization after the InitializeCompo nent() call

menuOptions.Men uItems.Clear()

menuOptions.Men uItems.Add("Exi t", AddressOf HandleNIExit)

'Following two items need handlers written for them, but they goto the

exit
handler for now

menuOptions.Men uItems.Add("Opt ion1", AddressOf HandleNIExit)

menuOptions.Men uItems.Add("Opt ion2", AddressOf HandleNIExit)

NotifyIcon1.Con textMenu = menuOptions

End Sub

AND

Sub HandleNIExit(By Val sender As Object, ByVal e As System.EventArg s)

Application.Exi t()

End Sub

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

message
news:%2******** ********@TK2MSF TNGP11.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.Componen tModel.Componen t
>
> ' Component designer generated code omitted.
>
> Public Shared Sub Main
> Dim app as New Component1
> Application.Run ()
> End Sub
>
> Private Sub menuOptions_Cli ck(...) Handles menuOptions.Cli ck
> Dim dialog as New OptionsDialog
> dialog.ShowDial og()
> dialog.Dispose( )
> End Sub
>
> Private Sub menuExit_Click( ...) Handles menuExit.Click
> Application.Exi t()
> 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.co m> > wrote in message news:e%******** ********@TK2MSF TNGP12.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
482
by: balu | last post by:
Hello , I Had a problem in developing a application for getting a message over or above system tray . When we first logon into the yahoo messenger , whenever a new user logon ,The messenger will shows message above the system tray. for example " balu comes is on online " above system tray . whenever a new user logout ,The messenger...
3
9718
by: joe | last post by:
Hi guys, Is there any way to refresh the system tray. Every time the explorer crashes the notify icons are removed and I cannot see them when it comes back even when my application is running. I could not find any code to refresh the system tray in the KB articles
4
1770
by: Robert Samuel White | last post by:
Hi there. Can anyone point me to some good references or examples on how to create an independent tray program that can send triggers to external applications all designed inside the same solution? Basically, I want a tray program with a context menu of options (they can be checked or unchecked options) that when an action is taken gets...
10
3119
by: Crouchie1998 | last post by:
Hello To All You Real Programmers Out There!! There is an application called: "Tray It" Webpage: ---------- http://www.teamcti.com/trayit/trayit.htm Direct Download:
6
4751
by: MLH | last post by:
I am unsure how to do this. I want this tray to be used for certain print jobs - jobs that will prompt me to load the bypass tray with sheet labels. How to force this? Dunno. Its the HP LaserJet 4200.
2
3900
by: ericlangland | last post by:
Hi, I have a small managed code application (windows forms) that executes on startup and immidiatly minimizes to the system tray. It launches and shows the form when I double click it's small icon in the system tray. So far so good. I'd like for the app to maximize outside of the system tray when the Windows + ? combination keys are...
3
7914
by: Patrick Dugan | last post by:
I am using VS2005 (vb) and I have a program that starts when Windows boots up. Occasionally the icon that should appear in the system tray does not show up. The program is still running in memory but the tray icon is not there. If I start the program after Windows has booted up the icon shows every time. I am assuming that the reason is...
3
3306
by: Usman Jamil | last post by:
Hi I've a windows application that does a lengthy backup process. While the process is going on, I need to show a progress bar inside system tray or just above the system tray. Can someone please guide me how to show the progress bar out of the boundaries of the application form area and near the system tray. Regards Usman
0
856
chanderravi
by: chanderravi | last post by:
Hello How can I get the list of applications in the system tray? Thanks Ravi
0
7374
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7632
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7392
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5931
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5309
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4930
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3422
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1850
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
677
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.