NotifyIcon - changing icon

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I'm using the NotifyIcon to process some text files in the background
periodically. I want to display one icon in the task bar when the program is
in stand by mode, and I want to display another icon when it is in processing
mode. How can I do that? I have some pseudo code below:

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Try
If processing Then
NotifyIcon.Text = "Processing .."
NotifyIcon.Icon = New Icon("Busy.ico") 'the problem is here,
I added the icon file to the solution explorer, but it's not using it!
Else
NotifyIcon.Text = "Standing By"
NotifyIcon.Icon = New Icon("Normal.ico")
End If
Catch ex As Exception
End Try
End Sub
 
The way I did it was as follows...

Have an array of icons:
Dim Icons(2) As System.Drawing.Icon

Have your icons set as embedded (so they go into the resource file). Select
the icon in solution explore and change the build action to embedded.
Dim p As System.Reflection.Assembly
p = System.Reflection.Assembly.GetExecutingAssembly()
Icons(0) = New System.Drawing.Icon(p.GetManifestResourceStream(Me.GetType(),
"GreenBulb.ico"))
Icons(2) = New System.Drawing.Icon(p.GetManifestResourceStream(Me.GetType(),
"RedBulb.ico"))
Icons(1) = New System.Drawing.Icon(p.GetManifestResourceStream(Me.GetType(),
"YellowBulb.ico"))

Then change the icon as you need it.
ntfSystemInfo.Icon = Icons(Counter)

I hope this helps
Chris
 
Chris,

What advantage is it for an Icon to be in the resource file? Isn't
the resource file just a list of files for the solution/project?
Seems like if anything I would want the icon file inside the .exe
file. When I add an icon (from p =
System.Reflection.Assembly.GetExecutingAssembly(), build action
embedded) it doesn't change the size of the .exe file.

Thanks...
Forrest

The way I did it was as follows...

Have an array of icons:
Dim Icons(2) As System.Drawing.Icon

Have your icons set as embedded (so they go into the resource file). Select
the icon in solution explore and change the build action to embedded.
Dim p As System.Reflection.Assembly
p = System.Reflection.Assembly.GetExecutingAssembly()
Icons(0) = New System.Drawing.Icon(p.GetManifestResourceStream(Me.GetType(),
"GreenBulb.ico"))
Icons(2) = New System.Drawing.Icon(p.GetManifestResourceStream(Me.GetType(),
"RedBulb.ico"))
Icons(1) = New System.Drawing.Icon(p.GetManifestResourceStream(Me.GetType(),
"YellowBulb.ico"))

Then change the icon as you need it.
ntfSystemInfo.Icon = Icons(Counter)

I hope this helps
Chris
< snip >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top